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

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().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

First use code tags:

using UnityEngine;
using System.Collections;

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

}


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

Now remember classes are case sensitive so this will not work:

other.GetComponent<Enemy>().DealDamage(swordDamage);

because your enemy class is using a lowercase e not E so change the GetComponent call to:

other.GetComponent<enemy>().DealDamage(swordDamage);
1 Like

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) =)

1 Like

Actually, you are right. This is better.

thanks all ,thanks for reply :slight_smile: , i am beginner for unity