c# - Error: an object reference is required to access non static member -


using unityengine; using system.collections;  public class playermovement : monobehaviour {     public float movespeed;      private vector3 input;      void update () {         input = new vector3(input.getaxis ("horizontal"), 0, input.getaxis ("vertical"));         rigidbody.addforce(input * movespeed);     } } 

as of unity 5 unityengine.component.rigibody has been deprecated , using cause compiler error. instead need use getcomponent<rigidbody>(). in case, code looks like:

using unityengine; using system.collections;  public class playermovement : monobehaviour { public float movespeed;  private vector3 input;      void update ()      {         input = new vector3(input.getaxis ("horizontal"), 0, input.getaxis ("vertical"));         getcomponent<rigidbody>().addforce(input * movespeed);     } } 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -