Inheritance: MonoBehaviour
Exemplo n.º 1
0
    void Awake()
    {
        Instance = this;

        //Turn off the UI Canvas when the game starts..
        restartCanvasObject.SetActive(false);
    }
Exemplo n.º 2
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Exemplo n.º 3
0
    public void RestartGame()
    {
        RestartLevel.ResetLevel();
        PlayerScore.Score     = 0;
        GameOver.isPlayerDead = false;
        Time.timeScale        = 1f;

        SceneManager.LoadScene("MainScene");
    }
Exemplo n.º 4
0
 public void Awake()
 {
     if (RestartLevel.instance == null)
     {
         RestartLevel.instance = this;
         DontDestroyOnLoad(this);
     }
     else if (RestartLevel.instance != this)
     {
         gameObject.SetActive(false);
         Destroy(gameObject);
     }
     restartCanvas.SetActive(false);
 }
Exemplo n.º 5
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         if (instance != this)
         {
             DestroyImmediate(gameObject);
         }
     }
 }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (isPlayerDead)
        {
            if (timer.Equals(0f))
            {
                ExplosionSound.Play();
            }

            // Wait for a second
            timer += Time.deltaTime;
            if (timer > waitTime && !_gameOverText.enabled)
            {
                _gameOverText.enabled = true;
            }

            if (timer > (int)(waitTime * 3f))
            {
                RestartLevel.ResetLevel();
                SceneManager.LoadScene("StartScene");
            }
        }
    }
Exemplo n.º 7
0
 public void IsRestartLevel()
 {
     RestartLevel?.Invoke();
 }
Exemplo n.º 8
0
    void FixedUpdate()
    {
        GameObject   gc = GameObject.Find("GameController");
        RestartLevel r  = gc.GetComponent <RestartLevel> ();

        if (r.isPaused)
        {
            return;
        }
        if (target != null)
        {
            float howFar = getDistance();

            if (howFar <= maxDist)
            {
                //rotates the enemy ship to the player
                //from: http://answers.unity3d.com/questions/207505/following-ai-similar-to-snake-game.html
                Vector3 track = target.position - transform.position;

                Quaternion wantDir     = Quaternion.LookRotation(track, Vector3.up);
                Quaternion newRotation = Quaternion.RotateTowards(rigidbody.rotation, wantDir, 60 * Time.deltaTime);


                //look in the direction of the player
                rigidbody.MoveRotation(newRotation);

                //moves to the player
                //add thrust in the direction of movement
                if (rigidbody.velocity.magnitude < chaseSpeed && howFar >= minDist)
                {
                    checkSight();
                    //object avoidance
                    if (objectDetected == true)                       //if you detect an asteroid rotate away from it.

                    {
                        transform.Rotate(0, (-obstacleAngle * 3.0f), 0);
                        rigidbody.AddForce(transform.forward * thrustSpeed);
                    }
                    else                                                                  //if you do not detect and asteroid then move forward
                    {
                        rigidbody.AddForce(transform.forward * thrustSpeed);
                    }
                }
                else
                {
                    rigidbody.angularVelocity = Vector3.zero;
                }
            }
            else
            {
                Vector3 goHome = startPosition - transform.position;

                Quaternion wantDir      = Quaternion.LookRotation(goHome, Vector3.up);
                Quaternion newRotation2 = Quaternion.RotateTowards(rigidbody.rotation, wantDir, 60 * Time.deltaTime);

                rigidbody.MoveRotation(newRotation2);
                if (rigidbody.velocity.magnitude < patrolSpeed)
                {
                    rigidbody.AddForce(transform.forward * thrustSpeed);
                }
            }
        }
    }
Exemplo n.º 9
0
 public virtual void shoot()
 {
     //print (shotProperties.shotSpawn);
     if (user.tag == "Player")
     {
         bool firing = (Input.GetButton("Fire1") || Input.GetAxisRaw("FireHorizontal") != 0 ||
                        Input.GetAxisRaw("FireVertical") != 0);
         if (firing && Time.time > shotProperties.nextFire)
         {
             RestartLevel r = GameObject.Find("GameController").GetComponent <RestartLevel>();
             if (r.isPaused)
             {
                 //can't fire while paused, sorry
                 return;
             }
             if (burst && burstCounter >= shotProperties.burst)        //player shot all shots for burst
             {
                 if (Time.time > shotProperties.nextBurst)             //time between bursts has happened
                 {
                     burstCounter = 0;                                 //reset the burst
                 }
             }
             else
             {
                 shotProperties.nextFire = Time.time + shotProperties.fireRate;
                 if (burst)
                 {
                     shotProperties.nextBurst = Time.time + shotProperties.burstWait;
                 }
                 if (shotProperties.ammo == -5)                             //check for unlimited ammo weapon
                 {
                     //default weapon has -5 ammo, so it doesn't use ammo
                     spawnBullet();
                     audio.Play();
                 }
                 else
                 {
                     //we have a weapon that shoots ammo
                     //if it has 0 ammo left, switch to normal weapon
                     if (shotProperties.ammo <= 0)
                     {
                         GameObject       player           = GameObject.FindGameObjectWithTag("Player");
                         PlayerController playerController = (PlayerController)player.GetComponent(typeof(PlayerController));
                         playerController.resetWeapon();
                     }
                     //else subtract 1 bullet
                     else
                     {
                         shotProperties.ammo--;
                         spawnBullet();
                         if (shotProperties.oneLoop)
                         {
                             audio.Play();
                         }
                         else
                         {
                             if (!audio.isPlaying)
                             {
                                 audio.Play();
                             }
                         }
                     }
                 }
             }
         }
         else if (!firing)
         {
             if (!shotProperties.oneLoop && audio.isPlaying)
             {
                 audio.Stop();
             }
         }
     }
     else
     {
         ungatedShoot();
     }
 }
Exemplo n.º 10
0
 public void BackToStart()
 {
     RestartLevel.ResetLevel();
     Time.timeScale = 1f;
     SceneManager.LoadScene("StartScene");
 }
Exemplo n.º 11
0
 public void Awake()
 {
     instance = this;
 }
Exemplo n.º 12
0
 void Awake()
 {
     Instance = this;
     restartCanvasObject.SetActive(false);
 }
Exemplo n.º 13
0
    void OnTriggerEnter2D(Collider2D CollisionWith)
    {
        //Checks with what the player collided
        if (CollisionWith.gameObject.tag.ToUpper() == "KEYCARD")
        {
            //Picks up the keycard

            FindObjectOfType <AudioManager>().PlayAt("KeycardPickUp");

            GotKeycard = true;

            KeycardsCollected++;

            if (KeycardsCollected == KeycardsNeeded)
            {
                GotKeycard = true;
            }

            Debug.Log("Needed" + KeycardsNeeded);
            Debug.Log("Collected" + KeycardsCollected);

            CollisionWith.gameObject.SetActive(false);
        }
        else if (CollisionWith.gameObject.tag.ToUpper() == "ITEM")
        {
            //Enables the picking up
            AtItem = true;

            LastHit = CollisionWith.gameObject;
        }
        else if (CollisionWith.gameObject.tag.ToUpper() == "LIGHT")
        {
            //Tells the enemy if the player is touching light
            Illuminated = true;
        }
        else if (CollisionWith.gameObject.tag.ToUpper() == "SMOKE")
        {
            //Checks how much smoke the player is standing in
            SmokeCounter++;
        }
        else if (CollisionWith.gameObject.tag.ToUpper() == "DEATH")
        {
            //Restarts the level if the player hit anything lethal
            FindObjectOfType <AudioManager>().PlayAt("PlayerDeath");

            Illuminated = false;

            KeycardsCollected = 0;

            RestartLevel.Restart();
        }
        else if (CollisionWith.gameObject.tag.ToUpper() == "TURRET")
        {
            //Enables the turning off of turrets
            AtTurret = true;

            ThisTurret = CollisionWith.gameObject;
        }
        else if (CollisionWith.gameObject.name.ToUpper() == "PROJECTILE")
        {
            //Checks if the player got hit so the sound can play
            FindObjectOfType <AudioManager>().PlayAt("ProjectileHit");
        }
        else if (CollisionWith.gameObject.tag.ToUpper() == "PORTALGUN")
        {
            //Enables the portalgun as soon as the player found it
            PortalGunFound = true;

            GameObject.Find("PlayerGunSprite").GetComponent <SpriteRenderer>().enabled  = true;
            GameObject.Find("PlayerHandSprite").GetComponent <SpriteRenderer>().enabled = false;
        }
    }
 public void SendRestartLevel()
 {
     RestartLevel?.Invoke();
 }
Exemplo n.º 15
0
 private void SendRestartLevelEvent()
 {
     RestartLevel?.Invoke();
 }