Hi, I’m pretty new to c# and unity so please bare with me.
I want to transform.position a Gameobject on a grid by using collider.bounds.center as a vector 3 reference.
I am trying to do this through a tilescript which equals one tile in an array. When I instantiate the GameObject/PlayerPrefab I am able to clone the Gameobject onto each tile (which is what I want to do with the transform.position). However when I try to transform.position the GameObject nothing works.
public class TileScript : MonoBehaviour {
public Vector3 tileCenter;
public GameObject PlayerPrefab;
public PlayerScript Select;
public float x,y,z;
// Use this for initialization
void Start () {
//tileCenter = new Vector3 (x, 3, z);
x = this.transform.collider.bounds.center.x;
y = this.transform.collider.bounds.center.y;
z = this.transform.collider.bounds.center.z;
}
void Update () {
}
void OnMouseEnter() {
gameObject.transform.renderer.material.color = Color.blue;
}
void OnMouseExit() {
transform.renderer.material.color = Color.white;
}
public void OnMouseDown()
{
PlayerPrefab.transform.position = new Vector3 (x, 3, z);
//if (Select.selected == true)
//var Move = Instantiate(PlayerPrefab, new Vector3 (x,0,z), Quaternion.AngleAxis (0,Vector3.right));
//tileCenter = newPos;
//print (x);
}
}
I have tried multiple variations of transform.position, none seem to work. Any help would be appreciated, thanks.