Hello I am new to unity and I want to replicate frogger logs on water like system.
My issue is with detecting whenever player is on water or log.
So far best I had was it would test it once correctly but not again and again.
Code for LogDetector:
using UnityEngine;
using System.Collections;
public class LogDetector : MonoBehaviour
{
public WaterDetector WaterDetector;
public bool isLog;
// Use this for initialization
void Start()
{
Debug.Log("Not on log");
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
isLog = true;
WaterDetector.isWater = false;
// GetComponent<Wt>().isWater = true;
Debug.Log("Player on log");
}
}
And here is my code for waterDetector:
using UnityEngine;
using System.Collections;
public class WaterDetector : MonoBehaviour
{
public LogDetector LogDetector;
public bool isWater;
// Use this for initialization
void Start()
{
isWater = false;
Debug.Log("Not on water");
//GetComponent<LogDetector>();
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (LogDetector.isLog == true)
{
isWater = false;
}
if (LogDetector.isLog == false)
{
isWater = true;
Debug.Log("Player on water");
}
if (isWater == true)
{
//Destroy(GetComponent<PlayerController>());
Destroy(other.gameObject);
}
}
}
My only question is how can I fix this so it does as I intend it to do. I want it to scan for detection constantly as logs will be moving so player will end up off the logs if he doesnt move with them.
Thanks for help