- Home /
This question was
closed Apr 20 at 06:57 PM by
imanipourmeysam for the following reason:
Other
Question by
imanipourmeysam · Apr 20 at 05:50 PM ·
script.unity 4
what cause crash in this code
hello, I am learning unity and I want to copy an object and place each copy in a different position. I wrote this code, but it causes crashing unity. I can't understand why, would you explain why this code causes crash. here is the code :
void Start()
{
float currentXPosition = gameObject.transform.position.x;
float currentYPosition = gameObject.transform.position.y;
for(int i = 1; i != 10; i++)
{
Instantiate(gameObject, new Vector3(currentXPosition, currentYPosition, 1), Quaternion.identity);
currentXPosition += i * 0.03f;
currentYPosition += i * 0.03f;
}
}
Thanks,
Comment
Best Answer
Answer by imanipourmeysam · Apr 20 at 06:57 PM
I solved the problem by if condition,
if(gameObject.name == "mygameobjectname").
It's solved
Follow this Question
Related Questions
how to get script references by script ? 0 Answers
How can i convert this javascript line to csharp ? 1 Answer
Mechanic Animation error unity 4 3 Answers
Simulate cloth tear 1 Answer
How can I view my character's skeleton in unity 4? 0 Answers