Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Feb 06, 2015 at 05:31 PM by Graham-Dunnett for the following reason:

Duplicate Question

avatar image
0
Question by Toasterino · Feb 06, 2015 at 05:30 PM · collisiondamage

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);
     }
 }

Comment
Comments Locked
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1

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?

Comment
Comments Locked · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Toasterino · Feb 06, 2015 at 04:21 PM 0
Share

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.

avatar image Toasterino · Feb 06, 2015 at 04:52 PM 0
Share

haven't seen any

avatar image Toasterino · Feb 06, 2015 at 04:55 PM 0
Share

Scrip is attached to bullet and the enemy. Enemy health is 50 and damage is 10 bullet health is 1 and damage is 5

avatar image gjf · Feb 06, 2015 at 04:56 PM 0
Share

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges