示例#1
0
    // Update is called once per frame
    public virtual void Update()
    {
        healthSlider.value = health;

        if (transform.position.y < -15)
        {
            Destroy(this.gameObject);
        }

        if (health <= 0)
        {
            Destroy(this.gameObject);
        }

        /*if (ufoPos.position.x > transform.position.x)
         * {
         *  transform.localScale = new Vector3(-1, 1, 1); //face right
         *  tankRb.velocity = new Vector2(tankSpeed, tankRb.velocity.y); //move right
         * }
         *
         * if (ufoPos.position.x < transform.position.x)
         * {
         *  transform.localScale = new Vector3(1, 1, 1); //face left
         *  tankRb.velocity = new Vector2(-tankSpeed, tankRb.velocity.y); //move left
         * }
         *
         * if (ufoPos.position.x < transform.position.x + 2)
         * {
         *  transform.localScale = new Vector3(1, 1, 1); //face left
         *  tankRb.velocity = new Vector2(tankRb.velocity.x, tankRb.velocity.y); //move left
         * }
         *
         * if (ufoPos.position.x > transform.position.x - 2)
         * {
         *  transform.localScale = new Vector3(-1, 1, 1); //face right
         *  tankRb.velocity = new Vector2(tankRb.velocity.x, tankRb.velocity.y); //move left
         * }*/

        Mathf.Clamp(transform.position.x, -70, 70);

        if (ufoPos.position.y < shootingRange.position.y)
        {
            if (ufoPos.position.x < transform.position.x + 10 || ufoPos.position.x > transform.position.x - 10)
            {
                //StopAllCoroutines();

                if (timeBefFiring <= 0)
                {
                    theTB.CalculateFiring();
                    timeBefFiring = 2f;
                }
                else if (timeBefFiring > 0)
                {
                    timeBefFiring -= Time.deltaTime;
                }

                if (ufoPos.position.x > transform.position.x + 2)
                {
                    transform.localScale = new Vector3(-1, 1, 1);                     //face right
                    tankRb.velocity      = new Vector2(tankSpeed, tankRb.velocity.y); //move right
                }

                if (ufoPos.position.x < transform.position.x)
                {
                    transform.localScale = new Vector3(1, 1, 1);                       //face left
                    tankRb.velocity      = new Vector2(-tankSpeed, tankRb.velocity.y); //move left
                }
            }

            /*if (ufoPos.position.x < transform.position.x + 2)
             * {
             *  transform.localScale = new Vector3(1, 1, 1); //face left
             *  tankRb.velocity = new Vector2(tankRb.velocity.x, tankRb.velocity.y); //move left
             * }
             *
             * if (ufoPos.position.x > transform.position.x - 2)
             * {
             *  transform.localScale = new Vector3(-1, 1, 1); //face right
             *  tankRb.velocity = new Vector2(tankRb.velocity.x, tankRb.velocity.y); //move left
             * }*/
        }
        else if (ufoPos.position.y > shootingRange.position.y)
        {
            //ChangeMovementType(MovementType.stayIdle);

            if (timeBefMoving > 0)
            {
                timeBefMoving -= Time.deltaTime;
            }
            //float timeBefChange = 5f;

            /*if (timeBefMoving <= 0)
             * {
             *  //Patrol();
             *  //timeBefMoving = 5f;
             *  //timeBefChange = 5f;
             *  //Debug.Log("patrolling now");
             * } else if (timeBefMoving > 0)
             * {
             *  timeBefMoving -= Time.deltaTime;
             * }*/
        }
    }