c# - Unity Space Shooter tutorial : CS 1526 ,1525 error in unity 5 -
error cs1525: unexpected symbol ,', expecting
;' error cs1526: new expression requires () or [] after type
using unityengine; using system.collections; public class playercontrol : monobehaviour { public float xmax, xmin, zmax, zmin; public float speed ; void fixedupdate() { float movehorizontal = input.getaxis ("horizontal"); float movevertical = input.getaxis ("vertical"); vector3 movement = new vector3 (movehorizontal, 0.0f, movevertical); getcomponent<rigidbody>().velocity = movement* speed; getcomponent<rigidbody>().position = new vector3 ( mathf(getcomponent.<rigidbody>().position.x, xmax, xmin), 0.0f, mathf(getcomponent.<rigidbody>().position.z, zmax, zmin) ); } }
there several issues here. first of there getcomponent.<rigidbody>()
. .
there wrong. call should be
getcomponent<rigidbody>();
and keep in mind getcomponent()
call expensive. calling multiple times not unnecessary, can costly. if within update()
or gets called on per frame basis. if you're going reference component often, store it.
so end like
rigidbody rigid_body = getcomponent<rigidbody>(); //perhaps once on start()
and later on
vector3 current_position = rigid_body.position; rigid_body.position = new vector3 ( mathf(current_position.x, xmax, xmin), 0.0f, mathf(current_position.z, zmax, zmin) );
and perhaps i'm wrong, think trying clamp positional values? in case call
mathf.clamp(current_position.x, xmax, xmin)
so make sure have @ well.
note:
based on of mistakes , comments think may looking @ documentation, wrong language. documentation site great that.
make sure documentation's language set appropriately. can @ top right.
that explain of "mistakes" made , easy trap fall into.
Comments
Post a Comment