This is what I am trying to do: I am fairly new so please be as descriptive as possible so that I may learn what I’m doing wrong and (hopefully) not repeat those mistakes.
On my game I have a handle which rotates right or left depending on mouse input clicks on the GUI. That aspect works fine, when the handle rotates it goes through colliders which in turn are supposed to be detected by this script when ran. That part (in theory) works fine, except that it is not running everytime the object moves to a new collision box. So In essence I am trying to find a way to make the thing run the script every so often (roughly 1 second). From looking around it seems the method using invoke repeat won’t work with the way it’s written so I had to use a coroutine. My knowledge with coroutines is very weak, in the compiler I show no errors but when I try to execute the script within the play preview of unity an error appears:
“script error: OnTriggerStay2D The Message must have 0 or 1 parameters”
Because of this error it does not work so could someone please take the time and explain why I’m getting this error and how to make it go away. Or alternatively, a different means in which to repeat my script (the original context of the script is included in the bottom but disabled).
Note:The functions for the script are incomplete since it does little good to complete the conditions if it cannot even do part of it properly.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Throttle_Triggers : MonoBehaviour
{
private Collider2D other;
// Use this for initialization
void Start()
{
//Call your function
StartCoroutine(OnTriggerStay2D(other));
}
IEnumerator OnTriggerStay2D(Collider2D other, float delayTime = 0f)
{
yield return new WaitForSeconds(delayTime);
//You can then put your code below
//......your code
{
if (GetComponent<Collider2D>() && gameObject.name == "Throttle_Stop")
gameObject.tag = "Throttle_Stop";
else if (GetComponent<Collider2D>() && gameObject.name == "Throttle_1-3")
gameObject.tag = "Throttle_1-3";
else
gameObject.tag = "Throttle1-3";
}
}
// void OnTriggerStay2D(Collider2D other)
// {
// if (GetComponent<Collider2D>() && gameObject.name == "Throttle_Stop")
//{
// gameObject.tag = "Throttle_Stop1";
//}
//else if (GetComponent<Collider2D>() && gameObject.name == "Throttle_13")
//{
// gameObject.tag = "Throttle_13";
//}
//else
//{
// gameObject.tag = "Throttle_23";
//}
}
Please also be aware there are 3 handles which function much the same, so bear that in mind in your response.
Thank you for your time in reading this and hopefully helping me solve it.