private void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Exemple #2
0
    void Update()
    {
        gameObject.transform.rotation = initRotation;
        if (health > 0)
        {
            if (Input.GetKey(KeyCode.RightArrow))
            {
                if (player.curhealth == 0 || health < 5)
                {
                    Capsule.sprite = CapsuleRight;
                }
                else
                {
                    Capsule.sprite = ShieldCapiRight;
                }

                transform.position += Vector3.right * speed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                if (player.curhealth == 0 || health < 5)
                {
                    Capsule.sprite = CapsuleLeft;
                }
                else
                {
                    Capsule.sprite = ShieldCapiLeft;
                }

                transform.position += Vector3.left * speed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.UpArrow))
            {
                transform.position += Vector3.up * speed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.DownArrow))
            {
                transform.position += Vector3.down * speed * Time.deltaTime;
            }
            transform.position = new Vector3(
                Mathf.Clamp(transform.position.x, boundary.xMin, boundary.xMax),
                Mathf.Clamp(transform.position.y, boundary.yMin, boundary.yMax),
                0.0f
                );
        }
        else
        {
            BackMusic.Stop();
            Capsule.sprite = DeadCapsule;
            Invoke("KillCapi", 1);
        }
    }
 private void Awake()
 {
     if (backMusic == null)
     {
         backMusic   = this;
         back        = this.GetComponent <AudioSource>();
         back.loop   = true; //設置循環播放
         back.volume = 0.5f; //設置音量
         back.clip   = music;
         back.Play();        //播放背景音樂
         DontDestroyOnLoad(this);
     }
 }
Exemple #4
0
 private void Awake()
 {
     if (Instance != this)
     {
         if (Instance == null)
         {
             GetComponent <AudioSource>().Play();
             DontDestroyOnLoad(gameObject);
             Instance = this;
         }
         else
         {
             GetComponent <AudioSource>().Stop();
             Destroy(gameObject);
         }
     }
 }