Search Unity

When colliding with "Wall" object another is enabled.

Discussion in 'Scripting' started by rudigreig, May 22, 2019.

  1. rudigreig

    rudigreig

    Joined:
    Dec 11, 2018
    Posts:
    50
    In my car game, if the engine is hit, I want to enable a fire particle effect attached to the vehicle. I've tried instantiate, but that makes the fire object appear where the engine was hit, i want it to be enabled as it has to move with the vehicle. Here's what I tried but I'm not sure how to use the .setActive(true) function, please reply with a script and explanation please!
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Engine : MonoBehaviour
    6. {
    7.  
    8.     private void OnTriggerEnter(Collider other)
    9.     {
    10.         if (other.CompareTag("Wall"))
    11.         {
    12.             gameObject.setActive(true);
    13.         }
    14.  
    15.         if (other.CompareTag("Floor"))
    16.         {
    17.             gameObject.setActive(true);
    18.         }
    19.     }
    20.  
    21. }