- Home /
My Youtube coppied code isn't working
Hello, I followed a youtube video and wrote the code exactly as he did, but mine gets four errors, while his doesn't. I don't know if it's because we're using different versions of unity (Me: Unity 5, him: whatever one was around in 2011) or what happened. Here's the full code:
using UnityEngine; using System.Collections;
public class Chest : MonoBehaviour { public State state;
public enum State
{
open,
close,
inbetween
}
void Start()
{
State = Chest.State.close;
}
void Update()
{
}
public void OnMouseEnter ()
{
Debug.Log ("Enter");
}
public void OnMouseExit ()
{
}
public void OnMouseUp ()
{
if (State == Chest.State.close)
Open ();
else
Close ();
}
private void Open()
{
Animation.Play ("OpenAnime");
State = Chest.State.open;
}
private void Close()
{
}
}
First two errors say "The left-hand side of an assignment must be a variable, a property, or an indexer." This is referencing lines 17 & 46.
Third error says "Expression denotes a 'Type', where a 'variable', 'value' or 'method group' was expected." This one is referencing line 37.
The last error says " An object reference is required to access non-static member `UnityEngine.Animation.Play()'", and is referencing line 45.
Answer by Mehul-Rughani · May 04, 2015 at 04:28 AM
Try This.... Hope It Will Help You .. :)
using UnityEngine;
using System.Collections;
public enum State
{
open,
close,
inbetween
}
public class Test1231 : MonoBehaviour {
public State stateTest;
void Start()
{
stateTest = State.close;
}
void Update()
{
}
public void OnMouseEnter ()
{
Debug.Log ("Enter");
}
public void OnMouseExit ()
{
}
public void OnMouseUp ()
{
if (stateTest == State.close)
Open ();
else
Close ();
}
private void Open()
{
Debug.Log("Enterrr");
animation.Play("OpenAnime");
stateTest = State.open;
}
private void Close()
{
}
}
Ok, so I no longer have any errors, but I'm still not getting an open treasure chest. It shows "Enterrr" in the log, but no animation...
Thank you $$anonymous$$ehul for getting rid of the errors!! :-)
check ur animation.there is a fault in ur animation