Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Chellebell1689 · May 04, 2015 at 02:13 AM · non-staticassignmentexpression

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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()
     {
         
     }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chellebell1689 · May 06, 2015 at 09:53 PM 0
Share

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!! :-)

avatar image Mehul-Rughani · May 15, 2015 at 10:46 AM 0
Share

check ur animation.there is a fault in ur animation

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

anonymous functions with JavaScript? 2 Answers

Non-static Singleton implementation 1 Answer

Dynamically Adjust Height of Bar Chart (GetComponent error?) 2 Answers

Require inspector assignment? 5 Answers

Expressions in statements must only be executed for their side effects 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges