- Home /
Why "random" give same values to all prefabs ?
Hello everyone, am sure this is a very ridiculous issue but i couldn't figure out how to solve it, #the objective is this ;
-when 2 prefabs collide, each one of them go to a random position #how am i trying to do it ? void OnTriggerEnter (Collider collider) { if (collider.gameObject.CompareTag ("stand_enemy")) { hit = true; tmpTarget = new Vector3 (Random.Range (-10, 10), Random.Range (-5, 5), 0); Debug.Log (gameObject.name + ": " + targetPosition);
}
}
so this is suppose to assign a random Vector3 to the tmpTarget variable, however in the Debug line, the result is the same for each 2 collided prefabs, i tried to do this but also same result : gameObject.GetComponent ().tmpTarget = new Vector3 (Random.Range (-10, 10), Random.Range (-5, 5), 0);
thank you very much for your help, have a nice day
UPDATE: Full class to better understand the problem : UPDATE2: pastbin link for better visualization
i thought that wasn't necessary, i updated the topic, thank your for replying
And you do see different names for the printing of the game object in the Log?
Put the name of the script into GetComponent (SCRIPT) which contains the tmpTarget you are trying to retrieve/update. You haven't posted the code to show us what you actually DO with tmpTarget to make it update the positions.
Answer by meat5000 · Aug 24, 2013 at 03:02 PM
Your debug will say:
targetPosition=Vector3.MoveTowards(targetPosition,shipControl.myTransform.position, speed * Time.deltaTime);
As the debug is inside an enter function which will only execute once on enter. hit = true; and targetPosition gets updated but debug is not called again as the Collision function is not entered into again until next collision.
It should show differently after multiple enemy collisions.
Your answer
Follow this Question
Related Questions
Memory Game Question 1 Answer
Spawn A Random Prefab 2 Answers
Random platform spawning with current code? 0 Answers
instantiate a prefab from array and then changing it 1 Answer