예제 #1
0
파일: Ship.cs 프로젝트: kmnk/TestMissile
 void Update()
 {
     if (playable && Input.GetKey("space"))
     {
         launcher.Launch(target, transform.position, transform.rotation);
     }
 }
예제 #2
0
        public void Launch()
        {
            MissileLauncher launcher = _environmentCreator.GetPlayerLauncher();
            {
                if (!launcher)
                {
                    return;
                }

                launcher.Launch();
            }
        }
예제 #3
0
    private void Update()
    {
        if (isLocal)
        {
            HideCursor(gameMaster.IsGameInProgress());
            if (playerInput == PlayerInput.KEYBOARD)
            {
                if (isAlive)
                {
                    if (Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
                    {
                        core.SetThrottle(1f);
                    }
                    else if (Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W))
                    {
                        core.SetThrottle(-1f);
                    }
                    else
                    {
                        core.SetThrottle(0f);
                    }
                    if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
                    {
                        core.SetRudder(-1f);
                    }
                    else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A))
                    {
                        core.SetRudder(1f);
                    }
                    else
                    {
                        core.SetRudder(0f);
                    }
                }
                cameraAim = new Vector2(cameraAim.x + Input.GetAxis("Mouse X"), Mathf.Clamp(cameraAim.y - Input.GetAxis("Mouse Y"), -cameraMaxY_up, cameraMaxY_down));
                cameraPivot.transform.rotation = Quaternion.Euler(cameraAim.y, cameraAim.x, 0f);
                if (isAlive)
                {
                    if (Input.GetMouseButton(0))
                    {
                        turret.FireCannon(playerMask);
                    }
                    if (Input.GetMouseButton(1))
                    {
                        missileLauncher.Launch();
                    }
                }
            }

            if (isAlive)
            {
                Ray aimRay = mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
                if (Physics.Raycast(aimRay, out RaycastHit aimHit, 50000f, playerMask + (1 << 14)))
                {
                    //Debug.Log("Raycast hit: " + aimHit.transform.name);
                    if (aimHit.transform.gameObject.layer == 9 || aimHit.transform.gameObject.layer == 13)
                    {
                        KaijuCore enemy = aimHit.transform.root.Find("Kaiju").GetComponent <KaijuCore>();
                        //turret.UpdateAim(enemy.transform.position + Quaternion.Euler(0f, enemy.transform.Find("Ship Pivot").eulerAngles.y, 0f) * new Vector3(0f, 0.25f, -0.65f), enemy.GetMovement());//enemy.GetVelocity());
                        turret.UpdateAim(aimHit.point, enemy.GetMovement());
                        //Vector3 point = enemy.transform.position + Quaternion.Euler(0f, enemy.transform.Find("Ship Pivot").eulerAngles.y, 0f) * new Vector3(0f, 0.25f, -0.65f);
                        Vector3 point = aimHit.point;
                        Debug.DrawLine(point, turret.transform.position, Color.red);
                        crosshair.color = new Color(1f, 0.25f, 0f, 0.65f);
                    }
                    else
                    {
                        turret.UpdateAim(aimHit.point, Vector3.zero);
                        crosshair.color = new Color(1f, 1f, 1f, 0.65f);
                    }
                }
                else
                {
                    Vector3 targetPointTemp = mainCamera.gameObject.transform.position + aimRay.direction * 50000f;
                    if (targetPointTemp.y < 0f)
                    {
                        targetPointTemp = new Vector3(targetPointTemp.x, 0f, targetPointTemp.z);
                    }
                    turret.UpdateAim(targetPointTemp, Vector3.zero);
                    crosshair.color = new Color(0.75f, 0.75f, 0.75f, 0.50f);
                }
            }
        }