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"