I’m trying to instantiate a clone of an object at position X, then move the original object to position Y; however, the Position.Set() doesn’t seem to do anything. Both objects stay at the position X, even though setting gravity and velocity work fine.
The pieces of my code in question:
(The script function Update() on the original object)
void Update()
{
if (isFree == true && isActive == true)
{
if (Input.GetMouseButtonDown(0))
{
GameObject.Find("LaunchPoint").GetComponent<Loader>().Load();
transform.position.Set(Anchor.transform.position.x, Anchor.transform.position.y, Anchor.transform.position.z);
rigidbody.velocity.Set(0, 0, 0);
rigidbody.useGravity = false;
isFree = false;
GameObject.Find("Main Camera").GetComponent<FollowObject>().MoveToPos(transform.position);
}
}
}
Anchor is another gameobject in the scene that doesn’t move.
(The code on the object that does the ‘reloading’ (the copy bit)):
public class Loader : MonoBehaviour {
public GameObject target;
public void Load()
{
GameObject newTarget = (GameObject)Instantiate(target);
newTarget.transform.rotation.Set(target.transform.rotation.x, target.transform.rotation.y, target.transform.rotation.z, target.transform.rotation.w);
newTarget.rigidbody.velocity.Set(target.rigidbody.velocity.x, target.rigidbody.velocity.y, target.rigidbody.velocity.z);
newTarget.GetComponent<FollowMouse>().enabled = false;
}
// Update is called once per frame
void Update()
{
target = GameObject.Find(target.name);
}
}
I can’t understand why the position of the original object (first bit of code) doesn’t move the object. I’ve also tried it with number values (0,0,0) and it doesn’t do anything either, when everything else appears to work properly.