Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

I have no idea where i am going wrong!

Discussion in 'Scripting' started by Ralph1388, Aug 16, 2015.

  1. Ralph1388

    Ralph1388

    Joined:
    Jul 25, 2015
    Posts:
    24
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Damage : MonoBehaviour
    5. {
    6.     public int damage = 10;
    7.  
    8.     void OnCollisionEnter (Collision collision)
    9.     {
    10.         if(collision.gameObject.tag == "Enemy")
    11.         {      
    12.             collision.gameObject.SendMessage("Take Damage", damage, SendMessageOptions.DontRequireReceiver)
    13.         }
    14.     }
    15. }






    error CS8025: Parsing error
    and
    error CS1525: Unexpected symbol `}'




    i HAVE NO IDEA WHERE I AM GOING WRONG!
     
  2. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    You need a semi colon after
    collision.gameObject.SendMessage("Take Damage", damage, SendMessageOptions.DontRequireReceiver)
     
  3. Ralph1388

    Ralph1388

    Joined:
    Jul 25, 2015
    Posts:
    24
    Thank you! :D
     
    TheValar likes this.
  4. Ralph1388

    Ralph1388

    Joined:
    Jul 25, 2015
    Posts:
    24
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Health : MonoBehaviour
    5. {
    6.     public float hitPoints = 100f;
    7.     public float currentHitPoints;
    8.     public GameObject explosion;
    9.  
    10.     void Start ()
    11.     {
    12.         currentHitPoints = hitPoints;
    13.     }
    14.  
    15.     public void TakeDamage (float amt)
    16.     {
    17.         currentHitPoints -= amt;
    18.  
    19.         if( currentHitPoints<= 0)
    20.         {
    21.             currentHitPoints = 0;
    22.             Die()
    23.         }
    24.     }
    25.     void Die()
    26.     {
    27.         Debug.Log ("Enemy Object Has Died");
    28.     }
    29. }


    Sorry about this but when i debugged it gave me a same error what now?
     
  5. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Die() needs a ; at the end.
    If it gave you the same error, it usually means its the same error =) (it can mean many things, but can give you an idea of where to look)
     
  6. Ralph1388

    Ralph1388

    Joined:
    Jul 25, 2015
    Posts:
    24
    I see thanks but i dont see it on my console does this mean something is wrong in the script
     
  7. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    You dont see what? the debug.log in the die method? Are you calling the take damage script enough times to activate the die?
     
  8. Ralph1388

    Ralph1388

    Joined:
    Jul 25, 2015
    Posts:
    24

    well within my health and dmage script its still not working... i recheck both sc cripts 10x or more but something isnt working its not taking damage so mabe there is a problem with the script or collider
     
  9. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    Code (CSharp):
    1. collision.gameObject.SendMessage("Take Damage", damage, SendMessageOptions.DontRequireReceiver)
    Delete the space between Take Damage so it is TakeDamage.

    Like this -

    Code (CSharp):
    1. collision.gameObject.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver)