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. Dismiss Notice

Enemy Combat Script C# Code help needed

Discussion in 'Scripting' started by chang420, Sep 10, 2013.

  1. chang420

    chang420

    Joined:
    Sep 7, 2013
    Posts:
    6
  2. foxter888

    foxter888

    Joined:
    May 3, 2010
    Posts:
    530
    line 48 in your code since you are getting a component of type player health and the variable is of type player health you should put the string to be player health too, that's what you are doing wrong.
    PlayerHealth eh = blah blah ("PlayerHealth") something like that not enemy. you need to spend a bit of time reading that you are writing
     
  3. chang420

    chang420

    Joined:
    Sep 7, 2013
    Posts:
    6
  4. Julius.J

    Julius.J

    Joined:
    Jul 24, 2013
    Posts:
    33
    You should write it like this:

    Code (csharp):
    1.  
    2. PlayerHealth eh = (PlayerHealth)target.GetComponent(typeof(PlayerHealth));
    3.  
    and do you have a PlayerHealth class?

    Because unity doesn't think you do. Misspelling?

    your PlayerHealth class may be private

    you need a :

    Code (csharp):
    1.  
    2. public class PlayerHealth : MonoBehaviour
    3.  
     
    Last edited: Sep 10, 2013