How To Make An Object Appear On Collision...

Hi, I’m currently am making a 3d sort of adventure game where you move a cube around getting past certain obstacles, talking to people and more. I want my cube to have a water particle effect appear under it when it is on anything with water and hide when it is not. I have currently found and used this script. However with this script it requires the user to press a key which I don’t want. So I have tried to fix it but I get no result and I’m not sure as to why. I will show the original script and what I think should be replaced, but when I replace it unity runs it but when it collides with water nothing happens. I’d appreciate any help, I’m a beginner so sorry if this is some form of silly mistake.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaterParticleScript : MonoBehaviour
{
    public GameObject targetObject;
    private bool hideObject;
    void Start()
    {
        hideObject = true;
    }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.H))
        {
            hideObject = !hideObject;
        }
        if (hideObject)
        {
            targetObject.SetActive(false);
        }
        else if (!hideObject)
        {
            targetObject.SetActive(true);
        }
    }
}
//This is the original script I have found
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaterParticleScript : MonoBehaviour
{
    public GameObject targetObject;
    void Start()
    {
        targetObject.SetActive(false);
    }
  
  
    void OnCollisionEnter(Collision coll)
    {
        if (coll.collider.CompareTag("Water"))
        {
            targetObject.SetActive(true);
        }
         
    }
     
      
  
}
//This is what I think it should be, it runs but nothing happens
//Also I have my water tagged as "Water"

Try using:

void OnTriggerEnter(Collider coll)
{
}

change your collision to Is Trigger.

I have just tried this method now and it doesn’t seem to work. I have input void OnTriggerEnter(Collision coll) as void OnTriggerEnter(Collider coll) doesn’t work. I’m not sure why it doesn’t work, I have set the water object as a is trigger and it still doesn’t work. Please let me know if there is anything else I can try

Are you assigning the script to the object that is holding the water?

Put

Debug.Log(coll.gameObject.name);

in the OnTriggerEnter function, just to see if it’s correctly seeing a collider entering it’s collision. :slight_smile:

I forgot to add there is this message in the console which may be causing problems:
Script error: OnTriggerEnter
This message parameter has to be of type: Collider
also I have my script on my player with the target object as the water effect and I have a small pond which is tagged as water. I basically want the water particle effect to appear if it’s on or touching the water and disappear when not.
I have added the debug.log statement to the OnTrigger function and I get nothing so I guess it must not be colliding properly?
Thankyou for your help by the way.