Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Activate object from start

Discussion in 'Code Editors & IDEs' started by davicos, Jun 3, 2022.

  1. davicos

    davicos

    Joined:
    May 29, 2022
    Posts:
    7
    Hello everyone,
    first of all I'm sorry for my bad English, I'm still learning it.
    Second, I'm new member and I start to learn Unity by few days.. I would like to create a simple game: a roller ball that evade the cubes. So, now I would like to create a simple "death effect" like similar at an explosion, when cube hit player (the ball). I can't find any solution for to enable a "Explosion effect object" when player "die".
    My code are below. I hope I was clear.
    Thank you so much
    David

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DestroyOnCollision : MonoBehaviour
    6. {
    7.    
    8.     private void OnCollisionEnter(Collision collision)
    9.     {
    10.         if (collision.collider.CompareTag("Enemy"))
    11.         {
    12.             Destroy(collision.gameObject);
    13.            
    14.         }
    15.  
    16.     }
    17.     private void OnTriggerEnter(Collider other)
    18.     {
    19.        
    20.         if (other.CompareTag("Player"))
    21.         {
    22.             Destroy(other.gameObject);  
    23.         }
    24.  
    25.     }
    26.  
    27.  
    28. }
    29.  

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class EnemyContr : MonoBehaviour
    7. {
    8.     public float speed;
    9.     private void Update()
    10.     {
    11.         transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - speed * Time.deltaTime);
    12.     }
    13.  
    14. }
    15.  

    Player simply don't move. The cube comes towards him. It's just for try.. 1.PNG 2.PNG 3.PNG