Search Unity

Instantiate Object at object location when it collides with another object

Discussion in 'Physics' started by CranfillCrusher, Dec 16, 2017.

  1. CranfillCrusher

    CranfillCrusher

    Joined:
    Feb 15, 2017
    Posts:
    3
    Hello, I need help. I want to have a broken cube spawn when the player collides with an object making a cool destruction. When the broken cube instantiates, it spawns somewhere else. Any Ideas?

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class ObstacleDefeat : MonoBehaviour {

    public GameObject PlayerDestoryed;

    private GameObject Player;

    void Start () {
    Player = GameObject.FindWithTag("Player");
    }

    private void OnCollisionEnter(Collision other)
    {
    if (other.gameObject.CompareTag("Player") && Player != null)
    {
    Instantiate(PlayerDestoryed, Player.transform.position, Player.transform.rotation);
    Destroy(Player);
    }
    }
    }
     
  2. CranfillCrusher

    CranfillCrusher

    Joined:
    Feb 15, 2017
    Posts:
    3
    Nevermind, found out that the children were offset from the parent.