Transform not updating
Hey, so i'm using this code : using UnityEngine; using System.Collections;
public class Shoot : MonoBehaviour {
public Rigidbody Balle;
public Transform Pointdetir;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
Instantiate(Balle, Pointdetir.position, Pointdetir.rotation);
}
}
} (don't care about weird variable names, i'm frenchy) But i want the game to update the transform of the empty Pointdetir object. It doesn't. I go in the inspector while walking around, it doesn't update. Also, I'd like to be able to put the abject Pointdetir that's already in the scene, not the prefab, but it doesn't work.
Any help?
Thanks in advance!
So, you attached this script to something other than the player (because if it was the player, you could just use transform.position and would not have the problem).
Then you drag in the player object into the inspector field "Pointdetir" (as what you say sounds as if this thing should be updated while the player walks around, so I guess you want the coordinates of the player here).
If you assigned something else than the player and expect the transform to be updated: What is updating the position of this object? Is it a child of the player? Is there some other script attached to it?
As you say this is a prefab, I assume it is either a more complex object that you use in multiple scenes or something that you dynamically instantiate. If you instantiate it somewhere per code, you need to set the reference there as well as a prefab cannot reference scene objects.
Was useful, but I need the Pointdetir object, not the player's. Pointdetir is basically the barrel the bullet shoots from.
Well, if you select the the object in the scene (not the prefab of course), drag the barrel scene object (again: not prefab) to the Pointdetir field and then move the barrel, then the value of Pointdetir will change as it will reference the Transform of the barrel.
The script is not the problem here, there seems to be something wrong with how the objects get set up. Cannot see it from here, though. ;)