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

can anyone help me , i get this error but i cannot sholve

Discussion in 'Scripting' started by rofikcoga, Sep 19, 2015.

  1. rofikcoga

    rofikcoga

    Joined:
    Apr 8, 2015
    Posts:
    6
    anyone help me ,can i fix this

    enemy script:

    using UnityEngine;
    using System.Collections;

    public class enemy : MonoBehaviour {
    public void DealDamage(float x) { health -= x; }

    }
    error
    Assets/skrip/plyer/enemy1.cs(8,49): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

    and here skrip for sword

    using UnityEngine;
    using System.Collections;

    public class sword1 : MonoBehaviour {

    // Use this for initialization
    void Start () {
    }
    // Update is called once per frame
    void Update () {
    }
    void OnTriggerEnter(Collider other)
    {
    if(other.tag == "enemy")
    other.GetComponent<Enemy>().DealDamage(swordDamage);
    }
    }

    what i get error from enemy script anda cannot solve this
    Assets/skrip/plyer/enemy1.cs(8,49): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

    i need to apply damage to enemy with make public void what its get error
     
  2. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    First use code tags:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class enemy : MonoBehaviour {
    5. public void DealDamage(float x) { health -= x; }
    6.  
    7. }
    8.  
    9.  
    10. and here skrip for sword
    11.  
    12. using UnityEngine;
    13. using System.Collections;
    14.  
    15. public class sword1 : MonoBehaviour {
    16.  
    17. // Use this for initialization
    18. void Start () {
    19. }
    20. // Update is called once per frame
    21. void Update () {
    22. }
    23. void OnTriggerEnter(Collider other)
    24. {
    25. if(other.tag == "enemy")
    26. other.GetComponent<Enemy>().DealDamage(swordDamage);
    27. }
    28. }
    Now remember classes are case sensitive so this will not work:

    Code (CSharp):
    1. other.GetComponent<Enemy>().DealDamage(swordDamage);
    because your enemy class is using a lowercase e not E so change the GetComponent call to:

    Code (CSharp):
    1. other.GetComponent<enemy>().DealDamage(swordDamage);
     
    rofikcoga likes this.
  3. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I would instead advise you to not change your getcomponent to a lowercase e, and instead always make sure your classes are pascal case (UpperCasedForEachWord) =)
     
    Korno likes this.
  4. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    Actually, you are right. This is better.
     
  5. rofikcoga

    rofikcoga

    Joined:
    Apr 8, 2015
    Posts:
    6
    thanks all ,thanks for reply :) ,,, i am beginner for unity