- Home /
Duplicate Question
Collision damage in C#
I'm very new to Unity and i'm trying to make a top-down space shooter. My collision script doesn't work like i thought. Im trying to decrease enemy health but it gives me this error Assets/CollisionDamage.cs(12,33): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
using UnityEngine;
using System.Collections;
public class CollisionDamage : MonoBehaviour {
public int health = 1;
public int damage = 1;
void OnTriggerEnter2D(){
Debug.Log ("Trigger");
health-damage;
}
void Update() {
if (health <= 0) {
Die ();
}
}
void Die() {
Destroy (gameObject);
}
}
Answer by gjf · Feb 06, 2015 at 03:46 PM
as the error states, line 12 is the problem. that's not valid syntax in any language.
you probably mean:
health -= damage;
yes?
Yeah i tried that but the bullet doesn't do the damage i specify on the bullet. It does the damage i specified on the enemy, that it hits. I hope you understood something my English is not too good.
Scrip is attached to bullet and the enemy. Enemy health is 50 and damage is 10 bullet health is 1 and damage is 5
add some Debug.Log to see the value of each in OnTriggerEnter2D()
so you can see what's happening.
i'm guessing that you're new to program$$anonymous$$g/debugging as well as unity...
Follow this Question
Related Questions
How i make the player damage the enemy specific enemy he is colliding with 1 Answer
Why OnTriggerStay applies this action on all colliders 2 Answers
Deal Damage On Collision 3 Answers
Detecting Raycast collision on an enemy to deal damage 1 Answer
This collision Enemy health code suddenly stopped working. 1 Answer