Added a move script to control running time

Source: Internet
Author: User

Using Unityengine;
Using System.Collections;

public class Mysolidermove:monobehaviour
{

Transform _head;

Transform _gun;

public float worktime;
float _runtime=10;
BOOL IsEmpty;
Use this for initialization
void Start ()
{
_head = transform. Findchild ("Head");
_gun = transform. Findchild ("M16");


}

Update is called once per frame
void Update ()
{

Cursor.lockstate = cursorlockmode.locked;
_gun.forward = _head.forward; Point the gun to the center of the camera.
Move ();
Rotate ();
Run ();

Jump ();
}

[Serializefield]
float movespeed = 10f;
void Move ()
{
float horizontal = Input.getaxis ("horizontal");
float vertical = Input.getaxis ("vertical");


Vector3 Despos = vector3.right * horizontal + vector3.forward * VERTICAL;
Transform. Translate (Despos * time.deltatime * movespeed);

}

void Run ()
{
if (Input.getkey (keycode.leftshift) &&!isempty)//energy tank is not empty to enter the loop
{
Worktime + = Time.deltatime; Running time
Movespeed = 30f; Accelerated

if (worktime>_runtime)//If the running time exceeds the upper limit
{
IsEmpty = true; Set to Empty
}
}
Else
{
if (worktime>0)
{
Worktime-= Time.deltatime;
}
Else
{
worktime = 0;
IsEmpty = false;
}
Movespeed = 10f; In all other cases, the speed is normal.
}
}

void Jump ()
{
if (Input.getkeydown (keycode.space))
{
Transform. Translate (vector3.up*1.9f);
}
}

float RotationY = 0f;
[Serializefield]
float rotatespeed = 20f;
void Rotate ()
{
float MouseX = Input.getaxis ("Mouse X");
float Mousey = Input.getaxis ("Mouse Y");

Transform. Rotate (MouseX * vector3.up * rotatespeed);

RotationY + = Mousey;

RotationY = Mathf.clamp (RotationY,-60, 60); Controlling a person's vision

_head.localeulerangles = Vector3.left * RotationY;


public class Firstview:monobehaviour
//{

Direction sensitivity
public float Sensitivityx = 10F;
public float sensitivityy = 10F;

Top and bottom view (y view)
public float minimumy = -60f;
public float maximumy = 60F;

float RotationY = 0F;

void Update ()
// {
Depending on the speed (increment) of the mouse movement, the angle of rotation around the camera is obtained (processing x)
Float RotationX = transform.localeulerangles.y + Input.getaxis ("Mouse X") * SENSITIVITYX;

Based on the speed (increment) of the mouse movement, the angle of rotation of the camera up and down (processing y)
RotationY + = Input.getaxis ("Mouse Y") * SENSITIVITYY;
Angle limit. RotationY is less than min and returns min. Greater than Max, returns Max. Otherwise, return value
RotationY = Mathf.clamp (RotationY, Minimumy, maximumy);

Overall set the camera angle
Transform.localeulerangles = new Vector3 (-rotationy, RotationX, 0);
// }

void Start ()
// {
Make the rigid body isn't change rotation
if (rigidbody)
Rigidbody.freezerotation = true;
// }

}

}

Added a move script to control running time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.