I try to add a timer pickup to my countdowmTimer the trigger its work and destroy the object but no time add
Well the code there is no errors the trigger destroy the object but not adding the time I realy appreciate any help to finish my script pls. This Is My Code
using UnityEngine;
using System.Collections;
public class CountDownTimer : MonoBehaviour {
float timeRemaining = 60.0f;
public void addTime()
{
timeRemaining = 60.00f;
}
public void taketime()
{
timeRemaining -= 10.00f;
}
void Update () {
timeRemaining -= Time.deltaTime;
}
void OnGUI(){
if(timeRemaining > 0){
GUI.Label(new Rect(325, 30, 200, 50),
"Time Remaining : " +timeRemaining);
}
else{
Application.LoadLevel ("Game Over");
}
}
void OnTriggerEnter(Collider other)
{
// The switch statement checks what tag the other gameobject is, and reacts accordingly.
switch(other.gameObject.tag)
{
case "TimePickup":
Invoke("addTime", 3f);
break;
case "TimeOut":
Invoke("addTime", 3f);
break;
}
// Finally, this line destroys the gameObject the player collided with.
Destroy (GameObject.FindWithTag("TimePickup"));
}
}
The script is not quite well constructed, but I dont see any errors so far. Try to put Debug.Log to switch statement, to function addTime and look where is the problem. $$anonymous$$ake sure that your object really has a tag "TimePickup" and really has a trigger, but not a collider.
So, about the debugging. Try to use something like this and see which marks will be shown:
float timeRemaining = 60.0f;
public void addTime()
{
Debug.Log("$$anonymous$$ark 2");
timeRemaining = 60.00f;
}
public void taketime()
{
timeRemaining -= 10.00f;
}
void Update () {
timeRemaining -= Time.deltaTime;
}
void OnGUI(){
if(timeRemaining > 0){
GUI.Label(new Rect(325, 30, 200, 50),
"Time Remaining : " +timeRemaining);
}
else{
Application.LoadLevel ("Game Over");
}
}
void OnTriggerEnter(Collider other)
{
// The switch statement checks what tag the other gameobject is, and reacts accordingly.
switch(other.gameObject.tag)
{
case "TimePickup":
Debug.Log("$$anonymous$$ark 1");
Invoke("addTime", 3f);
break;
case "TimeOut":
Invoke("addTime", 3f);
break;
}
// Finally, this line destroys the gameObject the player collided with.
Destroy (GameObject.FindWithTag("TimePickup"));
}
Then it means that the problem is more likely not in the script, since the switch statement does not produce case expression. As I mentioned earlier, the problem might be in the tag or in the trigger.
i have verify the tag it s ok and i have rigid body and boxcolider as trigger
You should not post comment as an answer and should NOT mark it as the correct answer as well...
Sorry For That I am New, What I can Do If I Need To Continue That Discuss?
Answer by brunocoimbra · Nov 21, 2016 at 04:01 PM
Possible problems:
The collided object isn't tagged properly.
Player doesn't have a collider attached.
The collided object doesn't have a collider attached.
Player doesn't have a rigidbody.
Neither player's collider and the collided object's collider have the "isTrigger" box checked.
That script isn't attached to the Player.
Hope that helps.