Esempio n. 1
0
    void Start()
    {
        camSetting   = (SettingsStatic.CamSettings)SettingsManager.GetCameraSetting();
        camPlayerSet = false;

        ScoreKeeper.shots       = 0;
        ScoreKeeper.hits        = 0;
        ScoreKeeper.playerKills = 0;

        // TODO figure out a better way to do this
        LevelManager.isPaused = false;
        alive = true;

        ship       = gameObject.GetComponentInParent <ShipController>();
        ship.owner = gameObject.GetComponent <PlayerController>();

        targetIndicatorEnabled = false;
        velocityVector         = gameObject.transform.Find("VelocityVector").GetComponent <LineRenderer>();
        leadLine.enabled       = false;
        fc = gameObject.GetComponent <FiringController>();
        //ship.IFF = "green";

        menuCanvas  = GameObject.Find("MenuCanvas");
        hintsCanvas = GameObject.Find("HintsCanvas");
        // Debug.Log("Canvas found with name: " + menuCanvas.name);
        if (menuCanvas != null)
        {
            menuCanvas.SetActive(false);
        }
        if (hintsCanvas != null)
        {
            hintsCanvas.SetActive(false);
        }

        levelManager = GameObject.Find("LevelManager").GetComponent <LevelManager>();

        weaponText    = GameObject.Find("UIWeaponText").GetComponent <WeaponTextScript>();
        radarText     = GameObject.Find("UIRadarText").GetComponent <UIRadarText>();
        fuelSlider    = GameObject.Find("FuelSlider").GetComponent <Slider>();
        healthSlider  = GameObject.Find("HealthSlider").GetComponent <Slider>();
        contactsText  = GameObject.Find("UIContactsText").GetComponent <UIContactsText>();
        initialHealth = ship.health;

        selectedWeapon = Weapon.plasma;
        weaponText.SetUIWeapontext("Plasma");
        radarText.SetUIRadarText("off");
        SetCursorGame();

        // float distance = transform.position.z - Camera.main.transform.position.z;
        camera.fieldOfView = initialZoom;

        InvokeRepeating("UpdateUI", 0.00001f, 0.5f);
        Invoke("LateStart", 0.5f);
        lockIndicator.SetActive(false);

        ResizeMinimap();
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Escape) && !LevelManager.isPaused)
        {
            levelManager.PauseGame(menuCanvas);
        }

        if (alive)
        {
            if (!LevelManager.isPaused)
            {
                switch (camSetting)
                {
                case SettingsStatic.CamSettings.player:

                    desiredHeading += Input.GetAxis("Horizontal") * rotationSpeed;
                    float deltaTime = Time.deltaTime;
                    ship.Rotate(desiredHeading, deltaTime);

                    camera.fieldOfView            -= Input.GetAxis("MouseScrollWheel") * zoomSpeed;
                    camera.fieldOfView             = Mathf.Clamp(camera.fieldOfView, 30f, 80f);
                    camera.transform.localPosition = new Vector3(
                        0,
                        camera.fieldOfView * 0.1f,
                        -30f
                        );

                    break;

                case SettingsStatic.CamSettings.north:
                    camera.fieldOfView            -= Input.GetAxis("MouseScrollWheel") * zoomSpeed;
                    camera.fieldOfView             = Mathf.Clamp(camera.fieldOfView, 30f, 80f);
                    camera.transform.localPosition = new Vector3(
                        0,
                        camera.fieldOfView * 0.1f,
                        -30f
                        );

                    aimX -= Input.GetAxis("Horizontal");
                    aimY += Input.GetAxis("Vertical");

                    //Debug.Log("Aimx: " + aimX + " AimY: " + aimY);
                    Vector2 aimChange = new Vector2(aimX, aimY);
                    aimpoint += aimChange;


                    desiredHeading = NTools.HeadingFromVector(aimpoint);
                    ship.Rotate(desiredHeading, Time.deltaTime);

                    //Debug.Log(Input.GetAxis("Horizontal"));

                    aimX = 0f; aimY = 0f;
                    break;
                }

                if (Input.GetKey(KeyCode.W))
                {
                    if (!Input.GetKey(KeyCode.LeftShift))
                    {
                        ship.ThrustForward(1f);
                    }
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        ship.ThrustForward(2f);
                    }
                }

                if (Input.GetKey(KeyCode.A))
                {
                    if (!Input.GetKey(KeyCode.LeftShift))
                    {
                        ship.ThrustLeft(1f);
                    }
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        ship.ThrustLeft(2f);
                    }
                }

                if (Input.GetKey(KeyCode.S))
                {
                    if (!Input.GetKey(KeyCode.LeftShift))
                    {
                        ship.ThrustBackward(1f);
                    }
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        ship.ThrustBackward(2f);
                    }
                }

                if (Input.GetKey(KeyCode.D))
                {
                    if (!Input.GetKey(KeyCode.LeftShift))
                    {
                        ship.ThrustRight(1f);
                    }
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        ship.ThrustRight(2f);
                    }
                }

                if (Input.GetKey(KeyCode.X))
                {
                    ship.Stop();
                }

                if (Input.GetKeyDown(KeyCode.C))
                {
                    switch (camSetting)
                    {
                    case SettingsStatic.CamSettings.north:
                        camSetting   = SettingsStatic.CamSettings.player;
                        camPlayerSet = false;
                        break;

                    case SettingsStatic.CamSettings.player:
                        camSetting = SettingsStatic.CamSettings.north;
                        break;
                    }
                }

                if (Input.GetKeyDown(KeyCode.Tab))
                {
                    if (hintsCanvas != null)
                    {
                        hintsCanvas.SetActive(true);
                    }
                }
                if (Input.GetKeyUp(KeyCode.Tab))
                {
                    if (hintsCanvas != null)
                    {
                        hintsCanvas.SetActive(false);
                    }
                }

                if (Input.GetKeyDown(KeyCode.Mouse0))
                {
                    ship.FireWeapon(true);
                }
                if (Input.GetKeyUp(KeyCode.Mouse0))
                {
                    ship.FireWeapon(false);
                }
                if (Input.GetKeyDown(KeyCode.Mouse1))
                {
                    ship.SetNearestTarget();
                }

                if (Input.GetKeyDown(KeyCode.R))
                {
                    ship.ToggleRadar(); SetRadarText();
                }
                if (Input.GetKeyDown(KeyCode.T))
                {
                    ship.SetBoreTarget();
                }
                if (Input.GetKeyDown(KeyCode.Y))
                {
                    ship.SetNearestTarget();
                }

                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    SelectWeaponByNumber(1);
                }
                if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    SelectWeaponByNumber(2);
                }
                if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    SelectWeaponByNumber(3);
                }
                if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    SelectWeaponByNumber(4);
                }
            }


            UpdateVelocityVector();
            UpdateTargetIndicator();
            UpdateLeadLine();
            UpdateAimAid();
            UpdateOwnLockIndicator();
            UpdateIncomingLockIndicator();
            UpdateCamera();
        }
    }