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 someone tell me what is wrong with this script?

Discussion in 'Scripting' started by Phrygian, Jul 30, 2013.

  1. Phrygian

    Phrygian

    Joined:
    Jul 13, 2013
    Posts:
    10
    using UnityEngine;
    using System.Collections;

    public class TutorialAnimController : MonoBehaviour {

    // Link to the animated sprite
    private tk2dSpriteAnimator anim;

    // State variable to see if the character is walking.
    private bool walking = false;

    // Use this for initialization
    void Start () {
    // This script must be attached to the sprite to work.
    anim = GetComponent<tk2dSpriteAnimator>();
    }

    // This is called once the hit animation has compelted playing
    // It returns to playing whatever animation was active before hit
    // was playing.
    void HitCompleteDelegate(tk2dSpriteAnimator sprite, tk2dSpriteAnimationClip clip) {
    if (walking) {
    anim.Play("idle");
    }
    else {
    anim.Play("idle");
    }
    }

    var VCSuiteTest (VCDPadBase.GetInstance("dpad"));




    // Update is called once per frame
    void Update () {
    if (dpad.Left) {
    // Only play the clip if it is not already playing.
    // Calling play will restart the clip if it is already playing.
    if (!anim.IsPlaying("left")) {
    anim.Play("left");

    // The delegate is used here to return to the previously
    // playing clip after the "hit" animation is done playing.
    anim.AnimationCompleted = HitCompleteDelegate;
    }
    }

    if (dpad.Right) {
    if (!anim.IsPlaying("right")) {

    // Walk is a looping animation
    // A looping animation never completes...
    anim.Play("right");

    // We dont have any reason for detecting when it completes
    anim.AnimationCompleted = null;
    walking = true;
    }
    }

    if (dpad.Up) {
    if (!anim.IsPlaying("up")) {
    anim.Play("up");
    // We dont have any reason for detecting when it completes
    anim.AnimationCompleted = null;
    walking = false;
    }
    }
    if (dpad.Down) {
    if (!anim.IsPlaying("down")) {
    anim.Play("down");
    // We dont have any reason for detecting when it completes
    anim.AnimationCompleted = null;
    walking = false;
    }
    }
    }
    }





    All I get is 2 errors

    Error 1: Assets/phryg.cs(30,48): error CS1041: Identifier expected
    Error 2:Assets/phryg.cs(30,56): error CS1519: Unexpected symbol `)' in class, struct, or interface member declaration

    I'm pretty new to this stuff, so not flaming me to a horrible ego death would be appreciated.

    Thanks a lot!
     
  2. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    The problem is here

    var VCSuiteTest (VCDPadBase.GetInstance("dpad"));

    It's rather strange code and in C# you must initialize your variable declared with var immediately.

    PS Use Code tags to paste your code in your posts.
     
  3. Phrygian

    Phrygian

    Joined:
    Jul 13, 2013
    Posts:
    10
    This did it! Thanks Maklaud