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
Post a Comment