1. Control player Movement
Public floatSpeed =10f; Public floatXMin =-6.5f; Public floatXmax =6.5f; Public floatZmin =-4.5f; Public floatZmax =4.5f; voidfixedupdate () {floatH = Input.getaxis ("Horizontal"); floatv = Input.getaxis ("Vertical"); Vector3 Move=NewVector3 (H, 0f, V); Rigidbody.velocity= Speed *move; //limit the range of aircraft activity, this similar setting transform.positionRigidbody.position =NewVector3 (Mathf.clamp (rigidbody.position.x, XMin, xmax),0, Mathf.clamp (Rigidbody.position.z, Zmin, Zmax)); }
2. Set Boundaries (Destroy objects (bullets, enemy aircraft) beyond the boundary
DestroyByBoundary.cs script:
publicvoid ontriggerexit (Collider Other) { Destroy (other.gameobject); }
3. Set the meteorite to rotate around itself
float 5 ; void Start () { // random one angular speed rigidbody.angularvelocity = random.insideunitsphere * tumble; }
4, the speed positive and negative control movement direction positive and negative
Public float speed = 10f; // Speed is positive, the object moves forward, is negative, moves backwards rigidbody.velocity = speed * Transform.forward;
Space shooter shooting