How to make a new empty gameobject and set its position in Update() [c#]?
void Start () {
public GameObject taste = new GameObject();
}
void Update () {
taste.position = opponent.transform.position;
}
look at question above. Edit the code for me please so it is right
Answer by Rodolphito · Oct 24, 2015 at 11:15 PM
Move your taste GameObject declaration out of the Start method, and change line 5 to taste.transform.position = opponent.transform.position.
Although for some reason when creating a GameObject with new GameObject() it appears that accessing the transform component with taste.transform
returns null
, which is a problem I am currently encountering in my project. If anyone could shed some light on this problem, that would be nice.
I've never experienced an issue with not being able to access the transform on a newly created game object. What version of Unity are you using? Please post a separate question so we don't hijack this one (feel free to link it here, I read all comments).
Your answer
