Search Unity

} expected?

Discussion in 'Scripting' started by milo55545, Apr 13, 2017.

  1. milo55545

    milo55545

    Joined:
    Feb 28, 2017
    Posts:
    58
    So I have this code to play an animation, and wait 0.3 seconds. But for some reason I get the "} Expected" Error after "void Update () {". Here is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class splatanimhandle : MonoBehaviour {
    6.  
    7.     public Animator splat;
    8.     public bool isOnTitle;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.         StartCoroutine ("splatScene");
    13.         splat = GetComponent<Animator> ();
    14.         isOnTitle = true;
    15.     }
    16.    
    17.     // Update is called once per frame
    18.     void Update () {
    19.         IEnumerator splatScene() {
    20.             if (Input.GetKeyDown (KeyCode.Space) == true) {
    21.                 if (isOnTitle == true) {
    22.                     splat.Play ("splatanim");
    23.                     isOnTitle = false;
    24.                 }
    25.             }
    26.         }
    27.     }
    28.  
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    You're trying to define a method named splatScene inside another method (Update). You can't do that.
     
  3. milo55545

    milo55545

    Joined:
    Feb 28, 2017
    Posts:
    58
    Oh