c# - Unity Operator `-=' cannot be applied to operands of type `float' and `UnityEngine.Vector3' -
i want create character jump in unity, error: operator -=' cannot applied operands of type
float' , `unityengine.vector3'
public class exampleclass : monobehaviour { public float speed = 6.0f; public float jumpspeed = 8.0f; public float gravity = 20.0f; private vector3 movedirection = vector3.zero; void update() { charactercontroller controller = getcomponent<charactercontroller>(); if (controller.isgrounded) { movedirection = new vector3(input.getaxis("horizontal"), 0, input.getaxis("vertical")); movedirection = transform.transformdirection(movedirection); movedirection *= speed; if (input.getbutton("jump")) movedirection.y = jumpspeed; } movedirection.y -= gravity * time.deltatime; controller.move(movedirection * time.deltatime); } }
you cannot modify value single axis @ time, in c#. have reassign entire vector:
movedirection = new vector3(movedirection.x, movedirection.y - (gravity * time.deltatime), movedirection.z);
("copied" here...it same issue!)
c# unity3d
No comments:
Post a Comment