- Home /
I wrote this code to create 7 prefabs and rename the clones thus formed.This Code isnt working as anticipated.
Script doesnt rename the instantiated prefab.Rather, what i get is one clone and that not renamed. Why is it so?How do I correct it? I even tried on forums, but none of offered solutions worked. Posted: 03:47 AM 1 Hour Ago
using UnityEngine;
using System.Collections;
public class CreateNew : MonoBehaviour {
public Object PathFloorUnit;
// Use this for initialization
void Start () {
for(int x=0;x<=6;x=+1){
Object pathRef;
pathRef=Instantiate(PathFloorUnit,new Vector3(0,0,10*x),Quaternion.identity);
pathRef.name="newName";
}
}
// Update is called once per frame
void Update () {
}
}
I wrote it to rename an instantiated prefab but this is not working.Why?And how can i correct it?
Don't write very long subject lines. $$anonymous$$eep it short and put details in the question body.
Format your code
Don't repost the same question
hi select the code and select 101010 in the edit question so that we can understand the code
understood.I have made the code a bit more legible.this mistake will not be repeated.
Answer by wilgieseler · Oct 17, 2013 at 05:36 AM
Use x++
instead of x=+1
.
x++ increments x by one. x=+1 sets x to positive one. x+=1 adds 1 to x.
I want to add that I understood this mistake after I asked the question in forums.But it still didnt work because I hadnt reset the script (from inspector) after modifying and saving it in asset folder
Answer by gamerguy · Oct 17, 2013 at 05:50 AM
Yes that worked.Thanks.I want to add that the code in asset folder didnt change until i reset it.I think we have to reset the code after making changed in editor and saving.
If you can, mark the correct answer as correct so other people can see that it worked rather than adding a new answer.
Your answer
![](https://koobas.hobune.stream/wayback/20220613120100im_/https://answers.unity.com/themes/thub/images/avi.jpg)