Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Unity Error: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

$
0
0
This script (ShortRange tower bullet) acquires the monster component of another script (MonsterScript) and takes its health by the amount of damage this bullet does. The bullet is a public float. The second line of the else method is getting an error (health - damage;) void OnTriggerEnter(Collider co) { if (co.gameObject.tag == "Monster") { if (co.gameObject.GetComponent ().health <= 0) { co.gameObject.GetComponent ().Death(); Destroy (co.gameObject); }else{ co.gameObject.GetComponent ().myHealthBar.text = co.gameObject.GetComponent ().myHealthBar.text.Remove(co.gameObject.GetComponent ().myHealthBar.text.Length - 1 ); co.gameObject.GetComponent ().health - damage; } Here's the whole script public class ShortRangeTowerBullet : MonoBehaviour { // Speed public float speed = 10; // Target (set by Tower) public Transform target; //Damages the monster public float damage; void FixedUpdate() { // Still has a Target? if (target) { // Fly towards the target Vector3 dir = target.position - transform.position; rigidbody.velocity = dir.normalized * speed; } else { // Otherwise destroy self Destroy(gameObject); } } void OnTriggerEnter(Collider co) { if (co.gameObject.tag == "Monster") { if (co.gameObject.GetComponent ().health <= 0) { co.gameObject.GetComponent ().Death(); Destroy (co.gameObject); }else{ co.gameObject.GetComponent ().myHealthBar.text = co.gameObject.GetComponent ().myHealthBar.text.Remove(co.gameObject.GetComponent ().myHealthBar.text.Length - 1 ); co.gameObject.GetComponent ().health - damage; } } } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>