- Home /
Question by
nemesis13 · Jul 11, 2013 at 04:25 PM ·
error messageunexpectedsymbol
Why error unexpected symbol `_timeout`
using UnityEngine;
using System.Collections;
public class Door : MonoBehaviour {
public bool open;
private float _timeout;
public float Timeout;
private GameObject player;
public float MaxDistance = 3;
// Use this for initialization
void Start ()
{
player = GameObject.FindGameObjectWithTag("Player");
}
// Update is called once per frame
void Update ()
{
_timeout += Time.deltaTime;
if(Input.GetKeyDown(KeyCode.E)&_timeout>Timeout&Vector3.Distance(player.transform.position, transform.position)
{
_timeout = 0;
open = !open;
if(open == true)
{
transform.animation.CrossFade("open");
}
if(open == false)
{
transform.animation.CrossFade("Close");
}
}
}
}
Comment
yes I thought so, check my answer below.
Also mark it as correct if it solves your problem or comment if its not working :)
Answer by nemesis13 · Jul 11, 2013 at 05:30 PM
symbol`_timeour`
Please do not post comments as answers. Also you already commented the exact same thing! Did the answer help you?
Answer by InfiniBuzz · Jul 11, 2013 at 04:28 PM
Hi
Please tell us what line the error is in. I guess its here:
if(Input.GetKeyDown(KeyCode.E)&_timeout>Timeout&Vector3.Distance(player.transform.position, transform.position)
type this instead:
if(Input.GetKeyDown(KeyCode.E) && _timeout>Timeout && Vector3.Distance(player.transform.position, transform.position))
logic AND is &&
you also forgot the bracket
however this if statement probably wont work at all.
Vector3.Distance()
returns a float
which cannot be compared to a bool
.
you probably want to compare this too, something like:
if(Input.GetKeyDown(KeyCode.E) && _timeout>Timeout && Vector3.Distance(player.transform.position, transform.position) > 100)
Please also format your code properly next time :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613105920im_/https://answers.unity.com/themes/thub/images/avi.jpg)