- Home /
[Closed] Getting CS0029 error when I try to check position of an object
error specifically: Cannot implicitly convert type UnityEngine.Vector3' to
bool'
Have code in c# that finds any objects tagged as "redCircle" then checks to see if any of the objects are located at position (1,1) and if they are it deletes them. If it would work. Been searching around and tried a bunch of things to no avail. help would be much appreciated :D.
public void del() {
GameObject[] circleDel;
circleDel = GameObject.FindGameObjectsWithTag("redCircle");
for(int i = 0; i < circleDel.Length; i++)
{
if(circleDel[i].gameObject.transform.position = new Vector2(1,1)) {
Destroy(circleDel[i].gameObject);
}
}
}
Sorry if this is a stupid question, just started using unity properly today.
Answer by getyour411 · Jan 13, 2014 at 02:42 AM
Change your = to == in if block
Tried it before and doesn't work, comes up with a different error. ended up fixing it myself, thanks anyway :)
Code I used to fix it with:
Vector2 abc;
public void del() {
GameObject[] circleDel;
circleDel = GameObject.FindGameObjectsWithTag("redCircle");
for(int i = 0; i < circleDel.Length; i++)
{
abc = circleDel[i].gameObject.transform.position;
if(abc == new Vector2(1,1)) {
Destroy(circleDel[i].gameObject);
}
}
}
just made a separate vector to hold the position info and it works like a charm now :3
The initial error is from the single "=" in IF (see that all the time); I didn't notice you were comparing a Vector3/transform to a Vector2
Your answer
Follow this Question
Related Questions
Quiz Scoreboard 2 Answers
Getting list music array 1 Answer
Multiple Cars not working 1 Answer
iphone keyboard .. 1 Answer
Login String to Bool Errors 1 Answer