2016-10-18 9 views
0

私のやっていることは、タイマーが50から0にTime.deltaTimeを使用してカウントダウンすることです。私はピックアップコインを私はタイマーが3秒で追加したい場合は今PlayerControlスクリプトで。私のコードは以下の通りです。秒に秒を追加する

// PlusOrbオブジェクトをピックアップするとPlayerControlです。

public class PlayerCTRL : MonoBehaviour 
{ 

    public Text timerText; 
    public TimerCount timerScript; 
    public Image DamagedOverlay; 
    public float speed; 
    public Text CountText; 
    private int count; 
    public GameObject TakeDamage; 
    public Text scoreText; 
    public TEMPLE_score scoreScript; 
    public TEMPLE_GlobalSettings globalSettings; 

    void Start() 
    { 
     CountText.text = CoinCounter.ToString(); 
     playerLife = 3; 
     count = 0; 
     SetCountText(); 
     playerAS = GetComponent<AudioSource>(); 
     timerScript = GetComponent<TimerCount>(); 
     damaged = false; 
    } 

    void OnTriggerEnter2D(Collider2D other) 
    { 
     if (other.gameObject.CompareTag("PlusOrb")) 
     { 
      Destroy(other.gameObject); 
      count = count + 1; 
      SetCountText(); 
      //score 
      scoreScript.myscore += 2; 
      scoreText.text = scoreScript.myscore.ToString(); 
      //timer 
      timerScript.timer + 3f;// this is the problem i am having 
      PlayerPrefs.SetInt("CoinCount", PlayerPrefs.GetInt("CoinCount") + 1); 
     } 
    } 
} 

//これはタイマースクリプトです。

public class TimerCount : MonoBehaviour 
{ 
    public Text TimeText; 
    public float timer1 = 50; 
    float SceneTimer = 0; 
    TEMPLE_GlobalSettings globalSettings; 
    public Sprite lives0; 
    public GameObject Gore; 
    public PlayerCTRL PlayerController; 
    int ouch; 


    void Start() 
    { 
     timer1 = 50; 
    } 


    void Update() 
    { 
     this.GetComponent<Text>().text = timer1.ToString("F0"); 
     timer1 -= Time.deltaTime; 

     print(timer1); 
     if (timer1 < 1) 
     { 
      timer1 = 0; 
      PlayerController.playerLife = 0; 
      SceneTimer += Time.deltaTime; 
      //if (SceneTimer > 2) 
      //{ 
      //SceneManager.LoadScene("TEMPLE"); 
      //} 
     } 
    } 

    void GameOver() 
    { 
     GameObject thisGore = Instantiate(Gore, transform.position, transform.rotation) as GameObject; 
     thisGore.GetComponent<ParticleSystem>().Play(); 
     GameObject.Find("Lives").GetComponent<Image>().sprite = lives0; 
     Destroy(gameObject); 
    } 
} 

答えて

0

これはbasic C#のものである

timerScript.timer += 3f; 

それとも

timerScript.timer = timerScript.timer + 3f; 

timerScript.timer + 3;// this is the problem i am having 

を交換してください。あなたはUnityで作業する前にC#を学ぶべきです。そこには多くのチュートリアルがあります。

EDIT

あなたの質問で更新されたスクリプトでは、あなたのTimerCountスクリプトでtimerという名前の変数がありません。 TimerCountスクリプトの同様の変数名は、timer1という名前です。名前をtimerまたはtimerScript.timer1 += 3f;に変更する必要があります。

これは、基本的なC#を習得する必要があることを意味します。これを侮辱として服用しないでください。基本的なC#を理解する必要があるか、このようなより似たような質問をするでしょう。あなたが宣言されていない変数にアクセスしています。

+0

私はそれがうまくいくと思ったが、まだ動作しないと思った。あなたの答えに感謝の男。 –

+0

何がうまくいかないのですか?ちょうどそれが動作しないと言ってはいけない....正確に何が動作しないか教えてください – Programmer

+0

私はそれらのすべてを試して、今は赤い線を表示するタイマーtimerScript.timer = timerScript.timer + 3f;またはtimerScript.timer + = 3f; –

関連する問題