Pulling my hair out, trying to use Instantiate for the first time ever…
I can instantiate a copy of a prefab, but using the script below causes the prefab to be instantiated at the exact location of the “original” in scene.
What I’m trying to do, is instantiate at the original start location of the original in-scene prefab. Where am I going wrong? I store the location of the original prefab at the start, but it doesn’t seem to instantiate at that original location… ?
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class makenewcoin : MonoBehaviour {
public GameObject coinstartlocation ;
public Vector3 newcointransformstartlocation;
private Vector3 cointransform;
private Quaternion coinrotate;
private bool coinalreadycreated = false;
// Use this for initialization
void Start(){
Debug.Log ("location of coinstartlocation is:" + coinstartlocation.transform.position);
cointransform = coinstartlocation.transform.position;
coinrotate = coinstartlocation.transform.rotation;
}
void OnTriggerEnter(){
if (!coinalreadycreated) {
Instantiate (coinstartlocation, cointransform, coinrotate);
Debug.Log ("made a new coin at the location of gameobject: coin at" + cointransform);
coinalreadycreated = true;
}
}
void OnTriggerExit(){
coinalreadycreated = false;
}
}