- Home /
Question by
bschubert · May 31, 2019 at 09:58 PM ·
instantiateprefabtransform.position
prefab always instantiates at 0.0.0
no matter how I code the script to instantiate a prefab animation sprite, it always instantiates at 0,0,0.
public class MoveScript : MonoBehaviour
{
private bool isDead = false;
public GameObject cargo;
public GameObject explosion;
public int spdCtrl;
float directionY;
Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb= GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(0, 0);
}
// Update is called once per frame
void Update()
{
if (isDead==false) {
directionY = CrossPlatformInputManager.GetAxis("Vertical");
rb.velocity = new Vector2(0, directionY*spdCtrl);
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Death")
{
// GameObject explode = Instantiate(explosion) as GameObject;
// explode.transform.position = cargo.transform.position;
// explode.transform.rotation = cargo.transform.rotation;
Instantiate(explosion, new Vector2(cargo.transform.position.x, cargo.transform.position.y), Quaternion.identity );
isDead = true;
//explosion.transform.position = cargo.transform.position;
Debug.Log(cargo.transform.position);
Debug.Log(explosion.transform.position);
GameObject.Destroy(cargo);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
}
}
Comment
Answer by NoCandyIncluded · Jun 01, 2019 at 03:01 AM
Try, Instantiate(explosion, cargo.transform.position, Quaternion.identity); instead of Instantiate(explosion, new Vector2(cargo.transform.position.x, cargo.transform.position.y), Quaternion.identity );