This question was
closed Nov 29, 2016 at 10:20 PM by
Nova-1504 for the following reason:
The question is answered, right answer was accepted
Question by
Nova-1504 · Nov 29, 2016 at 07:33 PM ·
collisiononcollisionenterif statementcs1525||
CS1525 Unexpected symbol '=', HELP!!!
With this code,
using UnityEngine;
using System.Collections;
public class PainSound : MonoBehaviour {
public AudioClip whenHurt;
private AudioSource source;
void Awake () {
source = GetComponent<AudioSource>();
}
void Update () {
}
void OnCollisionEnter (Collision coll)
{
if (coll.relativeVelocity.magnitude > 30f && other.tag = "projectile" || other.tag = "car")
source.PlayOneShot(whenHurt,1F);
}
}
I get CS1525, Unexpected symbol '='. Why?
I need help urgently, project is due soon!
Comment
Change this
if (coll.relativeVelocity.magnitude > 30f && other.tag = "projectile" || other.tag = "car")
to this
if ((coll.relativeVelocity.magnitude > 30f) && ((other.tag == "projectile") || (other.tag == "car")))
A single equals sign =
is an assignment operator where two equals signs ==
is for a conditional statement.
Wait, now it says "other" doesn't exist. What'd I screw up?