Okay I was doing a tutorial and I was writing some collider script and everything seems fine but I keep getting this message that states cannot implicitly convert type string to bool
using UnityEngine;
using System.Collections;
public class DestroyByContact : MonoBehaviour
{
void OnTriggerEnter(Collider other) {
if (other.tag = "Boundary")
{
return;
}
Destroy (other.gameObject);
Destroy (gameObject);
}
}
Assets/Scripts/DestroyByContact.cs(7,17): error CS0029: Cannot implicitly convert type string' to bool’
Just to be clear. In c# = is assignment. So your original code if (other.tag = “Boundary” ) is assigning “Boundary” to other.tag And since this doesn’t return a true/false if is yelling at you.
== is the comparison operator. This returns true or false , if the two things are equal to each other.
So
x= 5; Make the variable x take the value of 5
x== 5 Ask if x is 5 and return true/false if it is, or is not.
a good way to improve your programming skillset is to read the error message thoroughly. the error is stating that you cannot convert STRING to BOOL.
so you should then think… ok, im clearly trying to set a string value to a boolean value
now, find… in your code, where you’re setting String = Bool.
A little hint for you; in programming = is used for setting == is used for comparison === is used for precision comparison (1 === 1) will return true; but (1 === 1.0) will return false. reason: left side is integer, right side is double.
Do not necro post or try to hijack other threads. Create your own thread so we can address your problem
When you post code, use code tags. There’s a sticky post in the scripting forum right at the top that explains how.
Did you actually read through this thread and what people have answered? You made the same mistake as the OP. So the post #2 applies to you just the same way.