Unity objects are always in the center of the viewport

tags: Unity  C#  3d  

Hang this code under the camera

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Trace : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        float x = Input.GetAxis("Horizontal");//Rotate the camera
        float y = Input.GetAxis("Vertical");
        gameObject.transform.RotateAround(gameObject.transform.position, Vector3.up, x);
        gameObject.transform.RotateAround(gameObject.transform.position, Vector3.right, y);

        GameObject cube = GameObject.Find("Cube");//Require the object facing the camera
        cube.transform.RotateAround(gameObject.transform.position, Vector3.up, x);
        cube.transform.RotateAround(gameObject.transform.position, Vector3.right, y);

    }
}

Intelligent Recommendation

Two common methods to position DIV to the center of viewport

Two common methods to position DIV to the center of viewport 1. It is known that DIV is high, and it is calculated to position to the video center. 2.DIV wide high...

Click on the object to move to the camera function in the center of the viewport

1. Create two cameras, one for the main camera, one is the target camera, hide after setting the position 2. Creating a script is mounted on the controller 3, Note: This script is only the function of...

The anchor point between the two objects in unity - X, Y, Z axis is always in parallel and aligned

A recent problem is how two objects in different directions can make his anchor point, that is, the X, Y, and Z axes always in parallel. After several days of reviewing the data, I found a way. as fol...

Unity Gizmos draws the camera's viewport, frustum and FOV

Unity Gizmos draws the camera's viewport, frustum and FOV First, the purpose Due to development needs, it is necessary to draw the camera's viewport, frustum, and FOV in order to observe some relation...

More Recommendation

viewport

background When we compare mobile browsers to desktop browsers, the most obvious difference is the screen size. Websites designed for desktop browsers display significantly less content in mobile brow...

viewport:{

<%@page language=“java” contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8”%> <%@ include file="/webView/include/taglib.jsp"%> <%@ ...

Unity Event Center Event Center

Usage supported by the event center Simple send event: Send string type event: Send multiple parameter events: Monitoring event: Events for listening to parameters: Remove event: Remove all listening ...

[Unity] Unity Pivot and Center issues

First talk about Pivot and Center When the objectPivot andWhen the center coordinates are different, there will be some problems. For example: Center Pivot You can see that the coordinate axis is obvi...

After setting the viewport, Colorbox cannot be displayed in the center of the iPhone

As shown above, Colorbox (version: 1.3.19 + jQuery 1.7.2) fails to display in the center of the screen in the iPhone browser. After checking for a long time, it is found that the viewport is set on th...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top