usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine; Public classSpin:monobehaviour { Public floatSpeed =3.0f; //Use this for initialization voidStart () {}//Update is called once per frame voidUpdate () {transform. Rotate (0, Speed,0, Space.world); }}
Using system.collections;using system.collections.generic;using Unityengine;public class Mouselook:monobehaviour { public enum Rotationaxes{mousexandy = 0,mousex = 1,mousey = 2,}public rotationaxes axes = rotationaxes.mousex;public float Sensitivityhor = 9.0f;public Float Sensivtiityvert = 9.0f;public float Minimumvert = -45.0f;public float MaxiimumVert = 4 5.0f;private float _rotationx = 0;//Use this for initializationvoid Start () {Rigidbody BODY = getcomponent<rigidbody& Gt (); if (BODY = null) {body.freezerotation = true;}} Update is called once per framevoid Update () {if (axes = = Rotationaxes.mousex) {transform. Rotate (0, Input.getaxis ("Mouse X") * sensitivityhor, 0);} else if (axes = = Rotationaxes.mousey) {_rotationx-= Input.getaxis ("Mouse Y") * Sensivtiityvert;_rotationx = Mathf.clamp ( _rotationx, Minimumvert, Maxiimumvert); float RotationY = Transform.localeulerangles.y;transform.localeulerangles = New Vector3 (_rotationx, RotationY, 0);} else {_rotationx-= Input.getaxis ("Mouse Y ") * Sensivtiityvert;_rotationx = Mathf.clamp (_rotationx, Minimumvert, Maxiimumvert); float delta = Input.getaxis ( "Mouse X") * sensitivityhor;float rotatuiny = transform.localeulerangles.y + delta;transform.localeulerangles = new Vecto R3 (_rotationx, Rotatuiny, 0);}}
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine; Public classFpsinput:monobehaviour { Public floatSpeed =6.0f; PrivateCharactercontroller _charactercontroller; Public floatGravity =-9.8f; //Use this for initialization voidStart () {_charactercontroller= getcomponent<Charactercontroller> (); } //Update is called once per frame voidUpdate () {floatDeltaX = Input.getaxis ("Horizontal") *Speed ; floatDeltaz = Input.getaxis ("Vertical") *Speed ; Vector3 Movement=NewVector3 (DeltaX,0, Deltaz); Movement=vector3.clampmagnitude (movement, speed); Movement.y=Gravity; Movement*=Time.deltatime; Movement=transform. Transformdirection (movement); _charactercontroller.move (movement); }}
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine; Public classRayshooter:monobehaviour {PrivateCamera _camera; //Use this for initialization voidStart () {_camera= getcomponent<camera> (); Cursor.lockstate=cursorlockmode.locked; Cursor.visible=false; } voidOngui () {intSize = A; floatPosX = _camera.pixelwidth/2-Size/4; floatPosY = _camera.pixelheight/2-Size/2; Gui. Label (NewRect (PosX, PosY, size, size),"*"); } //Update is called once per frame voidUpdate () {if(Input.getmousebuttondown (0) {Vector3 point=NewVector3 (_camera.pixelwidth/2, _camera.pixelheight/2,0); Ray Ray .=_camera. Screenpointtoray (point); Raycasthit hit; if(Physics.raycast (Ray, outHit )) {Gameobject Hitobject=Hit.transform.gameObject; Reactivetarget Target= hitobject.getcomponent<reactivetarget> (); if(Target! =NULL) {target. Reacttohit (); }Else{startcoroutine (Sphereindicator (hit.point)); } } } } PrivateIEnumerator sphereindicator (Vector3 pos) {Gameobject sphere=gameobject.createprimitive (Primitivetype.sphere); Sphere.transform.position=POS; yield return NewWaitforseconds (1); Destroy (Sphere); }}
A list of simple FPS-like game scripting under Unity Engine