Unity Learning--005: emulation of several game operation modes

Source: Internet
Author: User

Combine the previous role control and lens control to implement several integrated operations here

1. CF class first angle of view control mode

This type of manipulation will bind the camera to the head of the pig foot simulation first view

The move is based on Unity's own charactercontroller.move () approach.

First, determine the role of a camera and the following C # script








Controller. Simplemove (Forward * curspeed); }

When I test his movement, I'll look at it in a third view, click on the main camera to switch at any time.

Your own mobile script works well, can walk and jump, the angle of view is also consistent with the

The following changes the script, so that the lens and pig feet with the mouse rotation angle, the pig's foot and the lens y can be rotated, the lens can only rotate the x-axis part of the angle

Add transform to the Update method in the move script of the pig's foot. Rotate (New Vector3 (0,input.getaxis ("Mouse X"), 0) is the angle that changes the y-axis of the pig's foot.

Add the mouse disappears code in Awake void Awake () {screen.showcursor = false;} Here at the beginning of the development should be aware that the mouse does not disappear, only click to disappear

This is because the development of the initial mouse does not locate the game window, the system is displayed, when the window is clicked into the scope will disappear.

The following is a modified role move script

public float speed = 10.0F;    Make the mouse disappear    void Awake () {screen.showcursor = false;}    void Update ()    {        Charactercontroller controller = getcomponent<charactercontroller> ();        The character turns to        //transform. Rotate (0, Input.getaxis ("horizontal") * rotatespeed, 0);        Set the direction of movement X and z        Vector3 movedirection = transform. Transformdirection (New Vector3 (Input.getaxis ("horizontal"), 0, Input.getaxis ("Vertical"));              Simple Mobile        transform. Rotate (New Vector3 (0, Input.getaxis ("Mouse X"), 0));        Controller. Simplemove (movedirection * speed);    }

Then add a rotation angle script to the lens.

As the y-axis of the lens changes with the rotation of the pig's foot (move method does not) so we just modify the x-axis in the camera

void Update () {transform. Rotate (-input.getaxis ("Mouse Y"), 0, 0);}

Here is simply the introduction of the rotate angle problem, here the angle to do a lot of problems here, the angle of the problem is not to delve into

So as long as the screen is appropriate to add the crosshair is similar to CF and CS role Controller. You can also place this code in the move script and set the angle limit

Coefficients and other problems are the appropriate coefficients for testing.

 public float speed = 10.0F;    Transform Camerafirst;        Make the mouse disappear void Awake () {screen.showcursor = false;    Camerafirst = Gameobject.find ("Camera"). Transform;        } void Update () {Charactercontroller controller = getcomponent<charactercontroller> (); The character turns to//transform.        Rotate (0, Input.getaxis ("horizontal") * rotatespeed, 0); Set the direction of movement X and z Vector3 movedirection = transform.        Transformdirection (New Vector3 (Input.getaxis ("horizontal"), 0, Input.getaxis ("Vertical"));  Move camera angle if (Camerafirst.rotation.x-input.getaxis ("Mouse Y") *0.3 <= 0.5 && camerafirst.rotation.x        -Input.getaxis ("Mouse y") *0.3 >= -0.71) {camerafirst.rotate (-input.getaxis ("Mouse y"), 0, 0); }//Move the character angle transform.        Rotate (New Vector3 (0, Input.getaxis ("Mouse X"), 0)); Simply move the controller.    Simplemove (movedirection * speed); }

This makes it easy to implement the next first view.

2. World of Warcraft type control, through the third view of the camera with keyboard control WASD and mouse click on the target location to achieve

3. Dota,lol mode control, through fixed-angle camera and mouse critical push screen movement, character movement through the mouse click on the target point implementation.

4. Mobile side to simulate mobile scene by finger screen

Unity Learning--005: emulation of several game operation modes

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.