Search Unity

Can't make shattering object

Discussion in 'Editor & General Support' started by TheBigPaff, Jan 19, 2019.

  1. TheBigPaff

    TheBigPaff

    Joined:
    Jan 19, 2019
    Posts:
    3
    So I've made a shattering object script that instantiates a new object (made of little blocks), but the blocks always spawn in another position on another block instead of the collided block. If I write position as a parameter it doesn't even spawn anywhere. Help?

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Shattering : MonoBehaviour
    4. {
    5.  
    6.  
    7.     public GameObject ShatteringObject;
    8.     private void OnCollisionEnter(UnityEngine.Collision collisionInfo)
    9.     {
    10.         if(collisionInfo.gameObject.tag == "Player")
    11.         {
    12.             Instantiate(ShatteringObject);
    13.             Destroy(gameObject);
    14.         }
    15.        
    16.     }
    17.  
    18. }
    19.  
     
  2. Have you tried
    Code (CSharp):
    1. Instantiate(ShatteringObject, transform.position, Quaternion.identity, transform.parent);
    I assume you are putting this script on the object you wish to "shatter".
     
  3. TheBigPaff

    TheBigPaff

    Joined:
    Jan 19, 2019
    Posts:
    3
    Yes I'm putting the script on the object I want to destroy.
    Unfortunately the script still doesn't work. The game bbject gets destroyed but the Shattering Object doesn't spawn :(
     
  4. Console, errors?
     
  5. TheBigPaff

    TheBigPaff

    Joined:
    Jan 19, 2019
    Posts:
    3
    No console errors