- Home /
Question by
Max 4 · Jul 19, 2011 at 07:34 AM ·
syntax-errorbce0051
Destroy on range command
Ok, so here is my code:
function Update ()
{
transform.Rotate (Vector3 (0, 2, 0));
target = GameObject.FindWithTag("Player");
range = Vector3.Distance(target.transform.position, transform.position);
if (range<5)
{
Destroy (gameObject);
}
}
and here is the error it produces:
Assets/Player/ammoreplenish/ammospin.js(8,18): BCE0051: Operator '<' cannot be used with a left hand side of type 'function(int): System.Collections.Generic.IEnumerable' and a right hand side of type 'int'.
I don't understand what it's having a problem with. How do I fix it?
Comment
Best Answer
Answer by FLASHDENMARK · Jul 19, 2011 at 08:07 AM
Hi. You did not define the variable "range" and therefor it did not work.
function Update ()
{
transform.Rotate (Vector3 (0, 2, 0));
target = GameObject.FindWithTag("Player");
var range = Vector3.Distance(target.transform.position, transform.position);
if(range < 5)
{
Destroy (gameObject);
}
}
Here you go!
Your answer
![](https://koobas.hobune.stream/wayback/20220612150637im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Error CS1519! Base Character script error from BurgZerg Arcade 2 Answers
Code Not Working. Any Ideas? 2 Answers
Need help fixing syntax errors 1 Answer
Script error. Please Help! 4 Answers