示例#1
0
        private void FireOnPlayers()
        {
            var players = GameObject.FindGameObjectsWithTag("Player");

            foreach (var player in players)
            {
                var playerPosition = player.transform.position;
                if (!(Vector3.Distance(playerPosition, transform.position) < ActionRadius))
                {
                    continue;
                }

                var        ray = new Ray(transform.position, playerPosition - transform.position);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.transform.gameObject != player)
                    {
                        continue;
                    }
                }

                _ship.TurnTurrets(playerPosition);
                _ship.FireTurrets();
                return;
            }
        }
示例#2
0
    private void Aiming()
    {
        var        ray = new Ray(TpsCamera.position, TpsCamera.forward);
        RaycastHit hit;
        Vector3    aim;

        if (Physics.Raycast(ray, out hit))
        {
            aim = hit.point;
        }
        else
        {
            aim = TpsCamera.forward * 10000 + TpsCamera.position;
        }
        _shipControls.TurnTurrets(aim);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            CmdFire(aim);
        }
    }