When I click on the button it Instatiates the prefab but after that the prefab just flies away in a random direction.
Help would be appreciated. This is my script for the button and the turret.
Button: public GameObject Turret;
public GameObject ObjectSpawnPoint;
public void AddObject() {
Instantiate(Turret, ObjectSpawnPoint.transform.position, Quaternion.identity);
}
Controller:
RaycastHit hit;
Ray ray;
// Update is called once per frame
void Update () {
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity)) {
transform.position = hit.point;
}
}
private void OnCollisionEnter(Collision collision) {
if (collision.collider.gameObject) {
Debug.Log(gameObject.name);
}
}