/// <summary>
    /// Updates the player aiming
    /// </summary>
    void Update()
    {
        if (!Utilities.IsLevelLoaded())
        {
            return;
        }

        if (Utilities.IsPlayerControllable(gameObject))
        {
            Vector3 pos         = Input.mousePosition;
            Ray     mouseRay    = Camera.main.ScreenPointToRay(pos);
            Plane   playerPlane = new Plane(Vector3.up, transform.position);
            float   rayDistance = 0.0f;
            playerPlane.Raycast(mouseRay, out rayDistance);
            Vector3 castPoint   = mouseRay.GetPoint(rayDistance);
            Vector3 toCastPoint = castPoint - transform.position;

            pos.z = Camera.main.transform.position.z;
            toCastPoint.Normalize();

            m_controller.AimWeapon(castPoint);
            //Debug.Log(castPoint);

            if (Input.GetMouseButtonDown(0))
            {
                //Debug.DrawRay(mouseRay.origin, mouseRay.direction);
                Debug.DrawRay(castPoint, Vector3.up, Color.green, 1.0f);
                m_controller.FireWeapon();
            }
        }
    }
 private void AimAndFire(Vector3 targetPosition)
 {
     if (cannonController != null)
     {
         cannonController.AimWeapon(targetPosition);
         cannonController.FireWeapon();
     }
 }
Exemple #3
0
 void OnTriggerStay2D(Collider2D other)
 {
     if (other.gameObject.tag == "Player")
     {
         //Debug.Log("player within range");
         playerPosition = other.transform.position;
         controller.AimWeapon(playerPosition);
         controller.FireWeapon();
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (GameInformation.IsPVP() && !controllable)
        {
            return;
        }

        mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        controller.AimWeapon(mousePos);

        if (Input.GetMouseButtonDown(0))
        {
            controller.FireWeapon();
        }
    }