Unity3d Click a button to achieve the conversion between the camera, click on the added object, and use the keyboard for mobile, mouse rotation, zoom operation

Source: Internet
Author: User

Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
Using Unityengine.ui;

public class Build:monobehaviour {
Public Gameobject Camera_main;
Public Gameobject Camera_front;
public int cameraflag;


Public Vector3 POS;
  
Public Gameobject Abuild;
Public Dropdown DRP;
public float x, y;
public float speed= 10.0f;
void Start ()
{
Camera_main = Gameobject.find ("Camera");
Camera_front = Gameobject.find ("Camera_front");
Camera_front. SetActive (FALSE);
Cameraflag = 1;
}

void Update () {

Rotate the model by holding down the left mouse button
if (Input.getmousebutton (0) &&abuild!=null)
{

Left mouse button to move
y = Input.getaxis ("Mouse X") * time.deltatime * speed;
x = Input.getaxis ("Mouse Y") * time.deltatime * speed;
Abuild.transform.Rotate (New Vector3 (x, y, 0));

}

Keyboard to move the model around the next key
if (Input.getaxis ("horizontal")! = 0 && Abuild! = null)
{
Abuild.transform.Translate (Input.getaxis ("Horizontal") * 3, 0, 0);
}
if (Input.getaxis ("Vertical")! = 0 && Abuild! = null)
{
Abuild.transform.Translate (0, 0,input.getaxis ("Vertical") * 3);
}

The mouse pulley realizes the model's contraction
if (Input.getaxis ("Mouse scrollwheel")! = 0)
{
Abuild.transform.localScale + = new Vector3 (Input.getaxis ("Mouse scrollwheel"), Input.getaxis ("Mouse scrollwheel"), Input.getaxis ("Mouse scrollwheel"));
}

If (Input.getmousebuttondown (1) && cameraflag > 0)
{
Ray Ray = Camera.main.ScreenPoin Ttoray (input.mouseposition);
Raycasthit hit;       

if (Physics.raycast (Ray, out-hit))
{
pos = hit.point;
if (Hit.transform.gameObject.name = = "Plane")
Pick = Gameobject.instantiate (Resources.load ("Checked"), POS, TRANSFO rm.rotation) as Gameobject;
Else
{
Debug.Log ("Checked Object! ");
Abuild = Hit.transform.gameObject;
}
}
}
//Implementing a function to convert between cameras
public void Changecamera ()
{
Cameraflag =-camerafla G
if (Cameraflag > 0)
{
Camera_main. SetActive (TRUE);
Camera_front. SetActive (FALSE);
}
Else
{
Camera_main. SetActive (FALSE);
Camera_front. SetActive (TRUE);
Abuild = null;
}
}
}

Unity3d Click a button to achieve the conversion between the camera, click on the added object, and use the keyboard for mobile, mouse rotation, zoom operation

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.