Ejemplo n.º 1
0
    void  Update()
    {
        if (!tankHealth.empty())
        {
            RaycastHit hit;
            Ray        ray = cameraPlayer.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, LayerMask.GetMask("Terrain")))
            {
                newRotation = Quaternion.LookRotation(hit.point - transform.position).eulerAngles;
            }
            //		if(Mathf.Abs (newRotation.y) - Mathf.Abs(transform.rotation.y) < 1f){
            //			Debug.Log("THEY ARE THE SAME");
            //		}

            //Debug.Log(newRotation.y);
            //Debug.Log(transform.rotation.eulerAngles.y);
            if (Mathf.Abs(newRotation.y - transform.rotation.eulerAngles.y) > 1f)
            {
                float currentRotationY = transform.rotation.eulerAngles.y;
                if (currentRotationY - newRotation.y < -180 || currentRotationY - newRotation.y < 180 && currentRotationY - newRotation.y >= 0)
                {
                    transform.Rotate(0f, -speed, 0f);
                }
                else
                {
                    transform.Rotate(0f, speed, 0f);
                }
            }
        }
    }
Ejemplo n.º 2
0
    void  Update()
    {
        if (!tankHealth.empty())
        {
            RaycastHit hit;
            Ray        ray = cameraPlayer.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, LayerMask.GetMask("Terrain")))
            {
                newRotation = Quaternion.LookRotation(hit.point - transform.position).eulerAngles;
            }
            //Debug.DrawRay(transform.position,hit.point);

            //Debug.Log(newRotation.x);
            //Debug.Log(transform.rotation.eulerAngles.x);
            if (Mathf.Abs(newRotation.x - transform.rotation.eulerAngles.x) > 1f)
            {
                float currentRotationX = transform.rotation.eulerAngles.x;
                //Debug.Log(currentRotationX);
                if ((currentRotationX - newRotation.x < -180 || currentRotationX - newRotation.x < 180 &&
                     currentRotationX - newRotation.x >= 0))
                {
                    //				&& ((currentRotationX >= 320 && currentRotationX <= 359)
                    //					|| (currentRotationX >= 0 && currentRotationX <= 10))){

                    transform.Rotate(-speed * Time.deltaTime, 0f, 0f);
                    //			}else if((currentRotationX >= 0 && currentRotationX <= 10)
                    //				|| (currentRotationX >= 320 && currentRotationX <= 359)){
                }
                else
                {
                    transform.Rotate(speed * Time.deltaTime, 0f, 0f);
                }
            }
        }
    }
Ejemplo n.º 3
0
    void Update()
    {
        if (!player || !scoreManager)
        {
            player       = GameObject.FindGameObjectWithTag("Allies");
            playerHealth = player.GetComponent <TankHealth>();
            scoreObject  = GameObject.FindGameObjectWithTag("ScoreManager");
            scoreManager = scoreObject.GetComponent <Scores>();
        }

        text.text = "Score: " + score;
        if (playerHealth.empty())
        {
            if (!scoreSent)
            {
                scoreManager.addScore(score);
                scoreSent = true;
            }
            if (isWaiting)
            {
                StartCoroutine(Wait());
            }
            if (!isWaiting)
            {
                SceneManager.LoadScene("MainMenu");
            }
        }
    }
Ejemplo n.º 4
0
    void  Update()
    {
        if (!AIhealth.empty())
        {
            if (!player)
            {
                player = tankControllerAI.player;
                return;
            }
            newRotation = Quaternion.LookRotation(player.position - transform.position).eulerAngles;

            if (Mathf.Abs(newRotation.y - transform.rotation.eulerAngles.y) > 1f)
            {
                float currentRotationY = transform.rotation.eulerAngles.y;
                if (currentRotationY - newRotation.y < -180 || currentRotationY - newRotation.y < 180 && currentRotationY - newRotation.y >= 0)
                {
                    transform.Rotate(0f, -speed, 0f);
                }
                else
                {
                    transform.Rotate(0f, speed, 0f);
                }
            }
        }
    }
Ejemplo n.º 5
0
 void OnCollisionEnter(Collision collision)
 {
     if (!tankHealthManager.empty() && collision.gameObject.tag == "Shell")
     {
         Shell shell = collision.collider.GetComponent <Shell>();
         // get the angle of the collision
         // get the angle ot the collision (bounse or not)
         if (armor < shell.armorPenetrationMM)
         {
             tankHealthManager.subtractTankHealth(shell.getDamage());
         }
     }
 }
Ejemplo n.º 6
0
    void Spawn()
    {
        if (spawnTime >= 20f)
        {
            spawnTime -= 1f;
        }
        if (playerHealth.empty())
        {
            return;
        }
        int spawnPointIndex = Random.Range(0, spawnPoints.Length);

        Instantiate(gobject, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
    }
    void Update()
    {
        if (isSinking)
        {
            transform.Translate(-Vector3.up * sinkSpeed * Time.deltaTime);
        }
        if (!canvas)
        {
            canvas       = GameObject.FindGameObjectWithTag("Canvas").GetComponent <Transform>();
            scoreManager = canvas.Find("Score").GetComponent <ScoreController>();
        }

        if (!AIhealth.empty())
        {
            if (timer > 0)
            {
                timer -= Time.deltaTime;
            }


            if (!player)
            {
                player       = GameObject.FindGameObjectWithTag("Allies").transform;
                playerHealth = player.GetComponent <TankHealth> ();
            }

            //if(playerHealth.getTankHealth() > 0 && AIhealth.getTankHealth() > 0){
            if (!stop && AIhealth.getTankHealth() > 0)
            {
                //nav.Resume();
                nav.SetDestination(player.position);
            }
            else if (!stop)
            {
                nav.enabled = false;
                //nav.Stop();
            }
        }
        else
        {
            if (!exploded)
            {
                Explode();
            }
            StartSinking();
        }
    }
Ejemplo n.º 8
0
    void Update()
    {
        if (!AIhealth.empty())
        {
            if (!player)
            {
                player = tankControllerAI.player;
                return;
            }

            RaycastHit hit;
            if (Physics.Raycast(firePoint.position, transform.forward, out hit, LayerMask.GetMask("Terrain")))
            {
                if (hit.collider.gameObject.tag == "Allies")
                {
                    //tankControllerAI.NavStop();
                    tankControllerAI.Fire();
                }
                else
                {
                    //tankControllerAI.NavResume();
                }
            }

            Vector3 errorCorrecting = new Vector3(0, 2, 0);
            newRotation = Quaternion.LookRotation(player.position + errorCorrecting - transform.position).eulerAngles;

            if (Mathf.Abs(newRotation.x - transform.rotation.eulerAngles.x) > 1f)
            {
                float currentRotationX = transform.rotation.eulerAngles.x;

                if ((currentRotationX - newRotation.x < -180 || currentRotationX - newRotation.x < 180 &&
                     currentRotationX - newRotation.x >= 0))
                {
                    transform.Rotate(-speed * Time.deltaTime, 0f, 0f);
                }
                else
                {
                    transform.Rotate(speed * Time.deltaTime, 0f, 0f);
                }
            }
        }
    }
Ejemplo n.º 9
0
    void Update()
    {
        if (!Input.GetButton("Ctrl") || playerHealth.empty())
        {
            Screen.lockCursor = true;
            Cursor.visible    = false;
            cameraZoom();
            rotationY += Input.GetAxis("Mouse X") * sensitivityX;

            rotationX += Input.GetAxis("Mouse Y") * sensitivityY;
            rotationX  = Mathf.Clamp(rotationX, minimumX, maximumX);

            transform.localEulerAngles = new Vector3(-rotationX, rotationY, 0);
        }
        else
        {
            Screen.lockCursor = false;
            Cursor.visible    = true;
        }
    }
Ejemplo n.º 10
0
    void  Update()
    {
        if (!tankHealth.empty())
        {
            float pitch = currentVelocity / maxSpeed + 0.3f;
            if ((pitch >= 0.3f && pitch <= 1.1f) || (pitch <= -0.3f && pitch >= -1.1f))
            {
                engineSource.pitch = pitch;
            }

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            Physics.Raycast(ray, out hit, LayerMask.GetMask("Terrain"));

            if (timer > 0)
            {
                timer -= Time.deltaTime;
            }

            if (!isGrounded() && Input.GetKey(KeyCode.R))
            {
                transform.rotation = new Quaternion(0, 0, 0, 0);
            }

            if (Input.GetKey(KeyCode.W) && isGrounded())
            {
                if (currentVelocity <= maxSpeed)
                {
                    currentVelocity += acceleration * Time.deltaTime;
                }
            }
            else if (Input.GetKey(KeyCode.S) && isGrounded())
            {
                if (currentVelocity >= -maxSpeed)
                {
                    currentVelocity -= acceleration * Time.deltaTime;
                }
            }
            else
            {
                if (currentVelocity > 0)
                {
                    currentVelocity -= acceleration * Time.deltaTime;
                }
                else if (currentVelocity < 0)
                {
                    currentVelocity += acceleration * Time.deltaTime;
                }
            }
            if (Mathf.Abs(currentVelocity) <= 0.05f)
            {
                currentVelocity = 0;
            }

            transform.Translate(new Vector3(0, 0, currentVelocity * Time.deltaTime));

            if (currentVelocity > 0)
            {
                MoveTracksForward();
            }
            else if (currentVelocity < 0)
            {
                MoveTracksBackward();
            }
            else
            {
                leftTrack.GearStatus  = 0;
                rightTrack.GearStatus = 0;
            }

            if (Input.GetKey(KeyCode.A) && isGrounded())
            {
                if (Input.GetKey(KeyCode.S))
                {
                    TurnRight();
                }
                else
                {
                    TurnLeft();
                }
            }

            if (Input.GetKey(KeyCode.D) && isGrounded())
            {
                if (Input.GetKey(KeyCode.S))
                {
                    TurnLeft();
                }
                else
                {
                    TurnRight();
                }
            }

            if (Input.GetButtonDown("Fire1") && isGrounded())
            {
                Fire();
            }
        }
        else
        {
            if (!exploded)
            {
                Explode();
            }
        }
    }