- Home /
Weird error while trying to call a void from another class
Hey everyone! Ive been trying for a while now to get this working, and cant seem to find the reason why i keep getting this error. What im trying to do is make platform disappear after 2 seconds that player enters the platform childs triggered collider. It seems to call the function but returns this error:
Couldn't extract exception string from exception (another exception of class 'InvalidCastException' was thrown while processing the stack trace)...
Heres the code:
void OnTriggerEnter(Collider c){
if(c.transform.parent.CompareTag("Disappearing")){
DisappearingPlatform dp = c.transform.parent.GetComponent<DisappearingPlatform> ();
dp.StartDisappearing();
}
}
And the class im trying to call:
using UnityEngine;
using System.Collections;
public class DisappearingPlatform : MonoBehaviour {
public float disappearDelay = 2f;
public float disappearTime = 5f;
float delay;
float cooldown;
bool notDisappearingAlready;
void Start(){
delay = disappearDelay;
cooldown = disappearTime;
notDisappearingAlready = true;
}
public void StartDisappearing(){
Disappear ();
}
void Disappear(){
if(notDisappearingAlready){
notDisappearingAlready = false;
delay -= Time.deltaTime;
}
if(delay <= 0){
transform.collider.enabled = false;
transform.renderer.enabled = false;
cooldown -= Time.deltaTime;
}
if(cooldown <= 0){
transform.collider.enabled = true;
transform.renderer.enabled = true;
cooldown = disappearTime;
delay = disappearDelay;
notDisappearingAlready = true;
}
}
}
Youch. It looks like the Unity environment is messing up and swallowing your error message.
At this point, you probably need to debug by "binary chop". Comment out parts of the program until the error goes away, narrow it down that way to a few liens of code.
Then, if it still isn't obvious, ask us about those lines.
Welcome to the art of debugging.
Answer by Kaaba · May 11, 2014 at 04:58 PM
Okay my bad, I had other OnTriggerStay which tried to look for animator, which these platforms didnt have. Checked if anim wasnt null and that fixed everything.
Your answer
Follow this Question
Related Questions
Public class used in another class (C#) 1 Answer
c# Unexpected symbol '=' in struct, class..... 1 Answer
Using JS class in C# 1 Answer