Objective: To Learn unity
Time:
Transmitter
Using unityengine; using system. collections; // declared attributes [addcomponentmenu ("camera-control/shooter")] [system. serializable] public class SHOOTER: monobehaviour {public transform bullet; public float movespeed = 0.10f; public float power = 1500f; void Update () {/*** input. getaxis ("horizontal") returns 1 to indicate horizontal to the right-1 to the left * input. getaxis ("vertical") returns 1 to indicate vertical up-1 to downward **/float H = input. getaxis ("horizontal") * time. deltatime * movespeed; float v = input. getaxis ("vertical") * time. deltatime * movespeed; this. transform. translate (H, V, 0); // press the blank key if (input. getkey (keycode. space) {// build a bullet according to the view panel transform instance = instantiate (bullet, transform. position, transform. rotation) as transform; // obtain the current direction vector3 FWD = transform. transformdirection (vector3.forward); // you can call this operation to assign a force instance to the bullet. rigidbody. addforce (FWD * power );}}}
Automatic destruction of bullets
Using unityengine; using system. collections; public class delbullet: monobehaviour {// use this for initialization void start () {destroy (gameobject, 3.0f); // destroy in the last 3 seconds }}
Unity3d Learning 1