c# - Unity Game Engine Tutorial? -


my game 2d rts, , wondering if knew of tutorial unity, or if well-versed in syntax of tell me have done wrong.

so, have camera object, , player object, both tagged. player object has sprite on it, , set rigidbody. script goes follows:

using unityengine; using system.collections;  public class aisciript : monobehaviour { private bool thisisplayer = true; private gameobject objplayer; private gameobject objcamera;  //input variables (variables used process , handle input) private vector3 inputrotation; private vector3 inputmovement;  //identity variables (variables specific game object) public float movespeed = 100f;  // calculation variables (variables used calculation) private vector3 tempvector; private vector3 tempvector2;  // use initialization void start() {     objplayer = (gameobject)gameobject.findwithtag("player");     objcamera = (gameobject)gameobject.findwithtag("maincamera");     if (gameobject.tag == "player")     {         thisisplayer = true;     } }  // update called once per frame void update() {     findinput();     processmovement();     if (thisisplayer == true)     {         handlecamera();     } }  void findinput() {     if (thisisplayer == true)     {         findplayerinput();     }     else     {         findaiinput();     } } void findplayerinput() {     //find vector move     inputmovement = new vector3(input.getaxis("horizontal"), 0, input.getaxis("vertical"));      //find vector mouse     tempvector2 = new vector3(screen.width * 0.5f, 0, screen.height * 0.5f);      // position of middle of screen     tempvector = input.mouseposition;      // find position of mouse on screen     tempvector.z = tempvector.y;      tempvector.y = 0;     debug.log(tempvector);     inputrotation = tempvector - tempvector2; } void findaiinput() {  } void processmovement() {     rigidbody.addforce(inputmovement.normalized * movespeed * time.deltatime);     objplayer.transform.rotation = quaternion.lookrotation(inputrotation);     objplayer.transform.eulerangles = new vector3(0, transform.eulerangles.y + 180, 0);     objplayer.transform.position = new vector3(transform.position.x, 0, transform.position.z); } void handlecamera() {     objcamera.transform.position = new vector3(transform.position.x, 15, transform.position.z);     objcamera.transform.eulerangles = new vector3(90, 0, 0); } } 

i figured post code in case, figure it's not issue, tried force move in start() , nothing happened.

you shouldn't using checks thisisplayer. should have separate classes player entity , non-player entities.

public variables exposed in editor , serialized entity when level saved. mean movespeed not set initialized in class.

you shouldn't add force rigidbody in update method. there's fixedupdate method that's used applying physics. because update called once per frame, no matter framerate, , fixedupdate called @ specific intervals, physics forces aren't affected framerate.

also, shouldn't try apply force , set position of transform of same object. strange things happen.

if go unity asset store (available in window menu within unity) there section called "complete projects" contains free tutorials. can't remember of them written in c#, javascript ones give ideas on how structure project.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -