- Home /
I'm trying to assign a public collider to some trigger events, but i keep getting "'GroundDetector.GroundCollider' is a 'field' but a 'type' was expected." message.
This is what i have so far, but i keep getting the error message "'GroundDetector.GroundCollider' is a 'field' but a 'type' was expected." All i'm trying to do is to set the public Collider to the three trigger events below (OnTriggerEnter, OnTriggerStay, OnTriggerExit)
using UnityEngine;
using System.Collections;
public class GroundDetector : MonoBehaviour
{
private bool onground;
public Collider GroundCollider;
void Start()
{
GroundCollider = GetComponent<Collider>();
}
void OnTriggerEnter(GroundCollider other)
{
onground = true;
}
void OnTriggerStay(GroundCollider other)
{
onground = true;
}
void OnTriggerExit(GroundCollider other)
{
onground = false;
}
}
Answer by zach-r-d · Jun 22, 2015 at 09:28 PM
For OnTriggerEnter, OnTriggerStay, and OnTriggerExit, you must write Collider instead of GroundCollider as the type of "other". GroundCollider, as the error states, is a field (not a type), and parameters need to be declared with a type.
If the desired behavior is to ignore the OnTrigger*** methods when the other collider is not GroundCollider, putting the following at the beginning of each function will do the trick:
if (other != GroundCollider) {
return;
}
Your answer
Follow this Question
Related Questions
Trigger not getting GameObject 2 Answers
Select collider for GetComponent? 1 Answer
Can't click gameobject when over another trigger? 1 Answer
Problem with the collider(I think) 0 Answers