hello fellow unity devs,
I have been incountering a problom with onTriggerEnter ,here is my c# script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class causeSwiming : MonoBehaviour {
public bool swiming;
public bool swimingInFrame;
public List<GameObject> TouchingObjects;
void Start()
{
TouchingObjects = new List<GameObject>();
}
void OnTriggerEnter(Collider collision)
{
if (TouchingObjects.Contains(collision.gameObject) == false)
{
TouchingObjects.Add(collision.gameObject);
}
}
void OnTriggerExit(Collider collision)
{
if (TouchingObjects.Contains(collision.gameObject) == true)
{
TouchingObjects.Remove(collision.gameObject);
}
}
// Update is called once per frame
void Update () {
swimingInFrame = false;
for (int i = 0; i < TouchingObjects.Count; i ++)
{
if (TouchingObjects*.CompareTag("water") == true)*
{
swimingInFrame = true;
}
}
if (swimingInFrame == true)
{
swiming = true;
}else
{
swiming = false;
}
- }*
}
The list TouchingObjects should contain all game objects with triggers touching the trigger of the object witch the script is a conponent of.But it has nothing in it.
sorry for any bad spelling.
thanks in advence.