Hi there!!
Straight to the point:
There are this two scripts:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public float distancePerSecond;
void Update () {
transform.Translate(0, 0, distancePerSecond * Time.deltaTime);
}
}
And this one:
using UnityEngine;
using System.Collections;
public class EnemySpawner : MonoBehaviour {
public GameObject enemy;
public GameObject player;
void Update() {
if (player.transform.position.z == 5.0f)
{
Instantiate (enemy);
}
else if(player.transform.position.z == 10.0f)
{
Destroy(player);
}
}
}
the thing is that no matter what i do (With my limited knowledges) the Instantiate and destroy functions doesn’t work unless i don’t use the Time.deltatime … I would really like to know why!! D:
I have been testing a variety of combinations of Event functions but none of them seems to work!
Any tips?
Thanks @pako and @rageingnonsense I'll take a look at it!! =) And ... about what i was trying to do ... well, it is not that much xP I was simply Re-Checking the Scripting Overview on the Unity Manual! =) And after the creating and destroying gameobjects part ... i tried to make a little practice exercise! =) It is simple: If the "Player's" 'Z' value is higher than 5 then an enemy will spawn ... and if it is higher than 10 or any other number the player will be destroyed! ... .as i said ... it isn't anything for a game .... just practicing what i learned!! ^^
– MaenorWell ... it worked perfectly!! ^^ Now i only have the problem that i need it to spawn only one time! xP That's why i was trying to do it more "Precise" hahahha
– Maenor@rageingnonsense So the right thing to do will be to "Re-Spawn" the player at origin instead of destroying him, right? And to avoid all this mess .... Use a "OnTrigger - Function" instead? xP .... My head is literally bleeding right now hahahhaha
– MaenorThanks man!! ^^ You were/are .... i dunno xP (I'm a Spanish guy) really helpful!! :') (y)
– Maenor@Bunny83 thanks for the clarifications. It makes real sense now. The book I had read to learn how to use Unity, was a good book, but it didn't explain very well this particular point, so I always felt that something was just not right with my way of thinking about this :-) Always eager to learn more :-) @Maenor sorry for the confusion.
– pako