error CS1525: Unexpected symbol `'
I am trying to apply damage to the player I got this error. error CS1525: Unexpected symbol (12,61)`' .
using UnityEngine;
using System.Collections;
using Opsive.ThirdPersonController.Wrappers;
using UnityEngine.UI;
public class damaging : MonoBehaviour {
public GameObject Player;
private health HealthScript;
void Awake () {
GameObject Player = GameObject.FindWithTag("Player");
HealthScript = Player.GetComponent<Health>();
}
void Damage () {
GetComponent().Damage(5, Vector3.zero, Vector3.zero);
}
}
Show to whole script so that I can check what is wrong with your script.
@importguru88 There is no way to GetComponent like you are getting. Correct ways is as follows.
GetComponent().Damage(5,Vector3.zero,Vector3.zero);
Answer by Mmmpies · Jun 02, 2016 at 07:34 AM
Careful when formatting your code, I've fixed it this time.
HealthScript = Player.GetComponent (Health);
Incidentally I don't think that'll help it'll just clear that error. Look at the variable declared at the top. Your HealthScript is of type health but your getComponent is finding Health.
Case is important in Unity so health and Health are 2 different things.
I suspect working out if your heath script is called
health
or
Health
Will fix that error with your syntax of GetComponent. I also think you'll get more errors as you fix that as @saud_ahmed020 say's that other GetComponent is all over the place!
Don't panic it gets easier even it seem at very slow pace :)
Answer by srikaran_p · Jun 02, 2016 at 08:19 AM
Just check out this webpage so that you actually know what you are doing with GetComponent.
https://unity3d.com/learn/tutorials/topics/scripting/getcomponent?playlist=17117