- Home /
Unity string to boolean: Boolean.parse not working
I'm trying to add something to my script to slow down movement when in the air, but the Collisioninfo.gameObject.tag function is asking for a boolean. I can't convert to boolean because for some reason Boolean.parse, and in general all Boolean-dot functions, do not work in my version of vscode. do you have any other ideas on how to do this, or solutions for the bool issue?
Thanks!
here's the code: public class player_cont : $$anonymous$$onoBehaviour { public Rigidbody rb; public float rlspeed; public float rlbase; public float rlslow; public string environment = "environment"; OnCollisionEnter(UnityEngine.Collision collisionInfo) { if (collisionInfo.gameObject.tag = environment) { rlspeed = rlbase; } else { rlspeed = rlslow; } }
// Update is called once per frame
void Update()
{
if (Input.Get$$anonymous$$ey("d"))
{
rb.AddForce(0, 0, rlspeed, Force$$anonymous$$ode.Acceleration);
}
if (Input.Get$$anonymous$$ey("a"))
{
rb.AddForce(0, 0, -rlspeed, Force$$anonymous$$ode.Acceleration);
}
}
}
Answer by ShadyProductions · Feb 19, 2020 at 09:03 AM
Your problem is your if statement
if (collisionInfo.gameObject.tag = environment)
it needs to be
if (collisionInfo.gameObject.tag == environment)
But it's better to just use
if (collisionInfo.gameObject.CompareTag(environment))
Your answer
Follow this Question
Related Questions
Shader graph adds background to my texture 1 Answer
updating an android app/Game 2 Answers
CAN I MAKE a farming game for Facebook ??? 1 Answer
Angry Birds Sling (3D) 0 Answers