So what I'm trying to do is spawn a prefab of smaller cubes onto the exact same position and rotation of a big cube so it 'breaks apart'. When I hit space, the big cube disappears as intended, but the smaller cubes instantiate from a distance.
Here's a .gif of what is happening.
void Update () {
if (Input.GetKeyDown("space"))
{
Instantiate(explo, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
}
Debug.Log("The Rotation");
Debug.Log(explo.transform.rotation);
Debug.Log("The Position");
Debug.Log(explo.transform.position);
}
Debug Log:
The Rotation
(0.0, 0.0, 0.0, 1.0)
The Position
(-5.5, -2.4, 3.5)
This is an extremely simple script and I've spent 2 days trying to find a similar problem to mine, but they all include Quaternion, which is not similar to my problem.
EDIT: Changing gameObject.transform.rotation to Quaternion.identity seems to entirely reset the rotation of the object.
EDIT2: 'explo' is defined before 'void start' as 'public GameObject explo', and is assigned via the Unity Editor.
explo
defined as and what game object do you have this script attached to? – Ben Rubinexplo
? Is this your exact code? I'm confused howexplo.localScale
compiles because I think it should beexplo.transform.localScale
– Ben Rubinexplo
has no scripts attached to it, and changingexplo.localScale
toexplo.transform.localScale
still returns the same result. (If there was an error before I hadn't noticed, it still compiled without error?) – Hellie ChartyDebug.Log(explo.transform.position);
is showing the position of your prefab, not of the position of the instance of that prefab that you added to your scene. If you want to see the position of the object in your scene, you want something likeGameObject cube = Instantiate(explo, gameObject.transform.position, Quaternion.identity) as GameObject;
and then show the position ofcube
. – Ben Rubin