Setting game object position on startup? (Beginner)

Hi everyone, I’m new to Unity, and I’m making a very basic car game. I want a flag to reposition itself when I start the game, but I cannot seem to figure it out. I tried this:
using UnityEngine;
using System.Collections;

public class FlagScript : MonoBehaviour {
	
	// Use this for initialization
	void Start () 
	{
		transform.position.Set(1,1,1);	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

This seems like it should work to me, but the object that I assign the script to simply refuses to move to the new position! Where am I going wrong? Thanks in advance!

transform.position = new Vector3(1,1,1);

Nope, im shooting blanks. I've never seen Set before either. But ofcourse google knows this.

2 Answers

2

transform.position returns a copy. So essentially you are setting position of a COPY of a variable you are trying to set.

(Might be different in unityscript. Not sure.)

Use:

transform.position = new Vector3(1,1,1);

or (i guess)

transform.position = transform.position.Set(1,1,1);

Brilliant! Thanks, I can’t believe I didn’t think of that. Good call! :slight_smile: Thanks so much!!

Glad it worked. You should use comments optrions for commenting. Answers are for, well answers only. Also people here will like you more if you give credit on what helps you. Cheers.