Question by
kradeism · Aug 30, 2015 at 04:11 PM ·
c# tutorialunexpected-symbol
getting unexpected symbol ';' error
I followed a tutorial on youtube on how to make a platformer game, followed his codes but it gets an unexpected symbol ';' error on the myAnim = this.gameObject.GetComponent; line. Why do I get this and how do I fix it?
using UnityEngine;
using System.Collections;
public class playerAnimatorController : MonoBehaviour {
public static playerAnimatorController instance;
Transform myTrans;
Animator myAnim;
Vector3 artScaleCache;
void Start () {
myAnim = this.gameObject.GetComponent<Animator()>;
myTrans = this.transform;
instance = this;
artScaleCache = myTrans.localScale ;
}
void FlipArt(float currentSpeed){
if ((currentSpeed < 0 && artScaleCache.x == 1)||(currentSpeed > 0 && artScaleCache.x == -1)) {
artScaleCache .x *= -1;
myTrans .localScale = artScaleCache;
}
}
public void UpdateSpeed(float currentSpeed){
myAnim .SetFloat ("Speed", currentSpeed);
FlipArt (currentSpeed);
}
public void UpdateIsGrounded(bool isGrounded){
myAnim .SetBool ("isGrounded", isGrounded);
}
}
Comment
Answer by Dave-Carlile · Aug 30, 2015 at 04:12 PM
Your syntax is a bit off...
myAnim = this.gameObject.GetComponent<Animator()>;
The part inside of should just be the class name. The parentheses are for calling the GetComponent< Animator> function and should be outside of the . So...
myAnim = this.gameObject.GetComponent<Animator>();
Your answer
![](https://koobas.hobune.stream/wayback/20220612002009im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scoring system help 1 Answer
Rocket Launcher Fires Explosion, But Not Rocket 2 Answers
Adding a sound to my Gun Script 0 Answers
Error CS1525|Unexpected " { " Please Help. Urgent. 1 Answer
Unexpected symbol error 0 Answers