Question by
Chrisfox · May 29, 2017 at 03:31 PM ·
c#objectvector3transform.positionontriggerenter2d
Falling object respawner
Hi, I'm still extremely new to Unity, and C#, so I'm sorry if the resolution to this is obvious, but what I'm trying to do here is make a falling object respawn to its original coordinates based off of its tag. I currently have this so far;
private Transform origTrans;
void Start() {
origTrans = transform.position;
}
void OnTriggerEnter2D (Collider other)
{
if (other.gameObject.tag == "Droplet") {
transform.position = origTrans;
}
}
}
However, I keep getting error CS0029 at origTrans = transform.position; and transform.position = origTrans;
I greatly appreciate any guidance I can be given. I'm uncertain as to what I'm doing wrong here.
Comment
Answer by ShadyProductions · May 29, 2017 at 07:59 PM
origTrans = transform.position;
.position property is a Vector3 type not a Transform type, you can see this if you hover over it in VS for example. you will have to use
private Vector3 origTrans;