示例#1
0
    // Update is called once per frame
    void Update()
    {
        tankHealth targetHealth = target.GetComponent <tankHealth>();

        if (!targetHealth)
        {
            return;
        }
        hpSlider.value = targetHealth.HPpercent();

        if (hpSlider.value <= 0f)
        {
            hpSlider.gameObject.SetActive(false);
        }
        else
        {
            hpSlider.gameObject.SetActive(true);
        }

        Vector3 tarPos;

        tarPos = target.transform.position;
        Vector2 pos = RectTransformUtility.WorldToScreenPoint(Camera.main, tarPos);

        hpSlider.transform.position = pos + offsetPos;
    }
示例#2
0
 // The image component of the slider.
 // Use this for initialization
 void Start()
 {
     targetObject       = GameObject.Find(objectName);
     targetHealthScript = targetObject.GetComponent <tankHealth>();
     slider.value       = 100;
     is_Dead            = false;
 }
示例#3
0
    public void CommunismEnhancement()
    {
        if (!m_IsCommunismed)
        {
            m_Chassis.transform.localScale   += new Vector3(0.6f, 0, 0.4f);
            m_Turret.transform.localScale    += new Vector3(0.4f, 0, 0.4f);
            m_Barrel.transform.localPosition += new Vector3(0.35f, 0, 0.2f);
            m_SecondBarrel = Instantiate(m_Barrel, m_Tank) as GameObject;
            m_SecondBarrel.transform.localPosition = m_Barrel.transform.localPosition - new Vector3(0.7f, 0, 0);
            tankShooting TKScript = gameObject.GetComponent <tankShooting>();
            TKScript.SetCommunismTrue();

            tankControl TKCcontroller = gameObject.GetComponent <tankControl>();
            TKCcontroller.SetSpeed(m_CMSpeed);

            tankHealth THScript = gameObject.GetComponent <tankHealth>();
            THScript.AddHealth(m_CMAddAmount);
            Rigidbody m_rigidbody = GetComponent <Rigidbody>();
            m_rigidbody.mass += m_CMIncreaseMass;

            m_IsCommunismed = true;
        }
        else
        {
            tankHealth tkHp = gameObject.GetComponent <tankHealth>();
            tkHp.RegenerateHealth(20f);
        }
    }
示例#4
0
 // Use this for initialization
 void Start()
 {
     targetObject       = GameObject.Find(objectName);
     targetHealthScript = targetObject.GetComponent <tankHealth>();
     gameoverObject     = GameObject.Find("Gameover");
     gameoverObject.SetActive(false);
 }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        tankHealth targetHealth = target.GetComponent <tankHealth>();

        if (!targetHealth)
        {
            return;
        }
        hpSlider.value = targetHealth.HPpercent();

        Vector3 tarPos;

        tarPos = target.transform.position + new Vector3(offsetPos.x, offsetPos.y, 0f);
        Vector3 lookAtSame = Camera.main.transform.TransformDirection(tarPos - from.transform.position);

        if (hpSlider.value <= 0f || lookAtSame.z >= 0f)
        {
            hpSlider.gameObject.SetActive(false);
        }
        else
        {
            hpSlider.gameObject.SetActive(true);
        }

        Vector2 pos = RectTransformUtility.WorldToScreenPoint(Camera.main, tarPos);

        hpSlider.transform.position = pos;
    }
示例#6
0
    // Update is called once per frame
    void Update()
    {
        tankHealth targetHealth = target.GetComponent <tankHealth>();

        if (!targetHealth)
        {
            return;
        }
        hpSlider.value = targetHealth.HPpercent();
    }
示例#7
0
    private void OnTriggerEnter(Collider other)
    {
        int playerMask = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("PlayerLayer"), 2f));

        if (other.gameObject.CompareTag("Player"))
        {
            tankHealth tkHealth = other.gameObject.GetComponent <tankHealth>();
            tkHealth.RegenerateHealth(m_RegenerateAmount);
            Destroy(gameObject);
        }
    }
示例#8
0
    private void OnTriggerEnter(Collider other)
    {
        //nblockHealth targetnBlockHealth = other.GetComponent<nblockHealth>();
        //targetnBlockHealth.TakeDamage(m_Damage);
        //Destroy(other.gameObject);

        //get target layer
        int blockMask  = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("NormalBlockLayer"), 2f));
        int playerMask = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("PlayerLayer"), 2f));
        int enemyMask  = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("EnemyLayer"), 2f));
        int EcubeMask  = (int)Mathf.Floor(Mathf.Log(LayerMask.GetMask("EnergyCubeLayer"), 2f));


        if (other.gameObject.layer == blockMask)
        {
            nblockHealth blockHealth = other.gameObject.GetComponent <nblockHealth>();
            blockHealth.TakeDamage(m_Damage);
            Destroy(gameObject);
        }

        if (other.gameObject.layer == enemyMask)
        {
            eTankHealth etkHealth = other.gameObject.GetComponent <eTankHealth>();
            etkHealth.TakeDamage(m_Damage);
            Destroy(gameObject);
        }

        if (other.gameObject.CompareTag("Player"))
        {
            tankHealth tkHealth = other.gameObject.GetComponent <tankHealth>();
            tkHealth.TakeDamage(m_Damage);
            Destroy(gameObject);
        }

        if (other.gameObject.layer == EcubeMask)
        {
            nblockHealth blockHealth = other.gameObject.GetComponent <nblockHealth>();
            blockHealth.TakeDamage(m_Damage);
            Destroy(gameObject);
        }

        if (other.gameObject.layer == 2 && other.gameObject.CompareTag("Walls"))
        {
            Destroy(gameObject);
        }
    }
示例#9
0
    void OnCollisionEnter(Collision collision)       //碰撞發生時呼叫
    //碰撞後產生爆炸

    {
        Instantiate(effect, transform.position, transform.rotation);
        if (collision.gameObject.tag == "enemy" || collision.gameObject.tag == "Player")
        {
            tankHealth targetHealth = collision.gameObject.GetComponent <tankHealth>();
            if (!targetHealth)
            {
                return;
            }
            float vol = Random.Range(volLowRange, volHighRange);
            tankSource.PlayOneShot(hitsound[Random.Range(0, hitsound.Length)], vol);
            float damage = collision.gameObject.tag == "Player"? 10f: 5f;
            damage += (gameObject.tag == "bullet"? 0f: 5f);
            targetHealth.TakeDamage(damage);
        }
        Destroy(gameObject);//刪除砲彈
        // }
    }
示例#10
0
    private void OnCollisionEnter(Collision other)
    {
        // find the rigidbody of the collision object
        Rigidbody targetRigidbody = other.gameObject.GetComponent <Rigidbody>();

        if (targetRigidbody.tag == "Enemy")
        {
            // only tanks will have rigidbody scripts
            if (targetRigidbody != null)
            {
                // Add an explosion force
                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                //find the TankHealth script associated with the rigidbody
                tankHealth targetHealth = targetRigidbody.GetComponent <tankHealth>();

                if (targetHealth != null)
                {
                    // calculate the amount of damge the target should take
                    // based on it's distance from the shell.
                    float damage = CalculateDamage(targetRigidbody.position);

                    // Deal this damage to the tank
                    targetHealth.TakeDamage(damage);
                }
            }

            // Unparent the particles from the shell
            m_ExplosionParticles.transform.parent = null;

            // Play the particle system
            m_ExplosionParticles.Play();

            // Once the particles have finished, destroy the gameObject they are on
            Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration);

            // Destroy the shell
            Destroy(gameObject);
        }
    }
    void OnDestroy()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, mExplosionRadius, mTankMask);
        for (int i = 0; i < colliders.Length; i++)
        {
            Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();
            if (!targetRigidbody)
            {
                continue;
            }
            targetRigidbody.AddExplosionForce(mExplosionForce, transform.position, mExplosionRadius);

            tankHealth targetHealth = targetRigidbody.GetComponent <tankHealth>();
            if (!targetHealth)
            {
                continue;
            }
            float damage = 10f;

            targetHealth.TakeDamage(damage);
        }
    }
    void Update()
    {
        if (Time.time - effectTime > 2)
        {
            effectTime = Time.time;
            Destroy(mMineEffectInst);
            mMineEffectInst = Instantiate(mMineEffect, new Vector3(0f, 0f, 0f), Quaternion.Euler(0f, 0f, 0f)) as GameObject;
            mMineEffectInst.transform.localPosition = new Vector3(0f, 0f, 0f);
            mMineEffectInst.transform.position      = gameObject.transform.position;
            mMineEffectInst.transform.parent        = gameObject.transform;
        }
        if (Time.time - countTime > mCountTime)
        {
            Instantiate(mExplosionEffect, transform.position, transform.rotation);
            Collider[] colliders = Physics.OverlapSphere(transform.position, mExplosionRadius, mTankMask);
            for (int i = 0; i < colliders.Length; i++)
            {
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();
                if (!targetRigidbody)
                {
                    continue;
                }
                targetRigidbody.AddExplosionForce(mExplosionForce, transform.position, mExplosionRadius);

                tankHealth targetHealth = targetRigidbody.GetComponent <tankHealth>();
                if (!targetHealth)
                {
                    continue;
                }
                float damage = 5f;

                targetHealth.TakeDamage(damage);
            }

            DestroyObject(gameObject);
        }
    }
示例#13
0
 // Use this for initialization
 void Start()
 {
     tkHP             = gameObject.transform.parent.gameObject.GetComponent <tankHealth>();
     m_tankCurrentHP  = tkHP.GetCurrentHP();
     m_CurrentHP.text = m_tankCurrentHP.ToString();
 }