当前位置:网站首页>Vuforia for unity add button to zoom in and out the model

Vuforia for unity add button to zoom in and out the model

2022-06-09 15:33:00 Djc8 small yard farmer

Specifically, the script is attached to the preform prefab On .

Doing this

take Vuforia for unity Import to Unity In the after , Locate the Vuforia On pre-set precast units provided .

There are the following prefabricated parts :ARCamera、CloudRecognition、CylinderTarget、FrameMarker、ImageTarget、Multitarget、ObjectTarget、TextRecognition、UserDefinedTarget、VirtualButton、Word.

We are here to ImageTarget Prefabrication as an example

stay Assets Add a C# Script (C# Script), named BtnControl, The script code is appended with .

Explain my script , I use this script by calling GUI.Button() Method , Draw buttons on the screen , After clicking the button , You can zoom in and out of the model , The script is rough . Forgive me .

Click on prefabricated parts ImageTarget, And then on the right side Inspector Click on Add Component

Enter script name :BtnControl( notes : When you type in , It should be automatically associated with this file ), Then return.

Then you can start dragging the precast units to Hierarchy Start using on . BtnControl.cs The script code is as follows

using UnityEngine;
using System.Collections;

public class BtnControl: MonoBehaviour {

    void OnGUI() {
        
        if (GUI.Button(new Rect(10, 50, 200, 50), " Zoom in "))
        {
            Vector3 v3 = transform.localScale;

            transform.localScale = new Vector3(v3.x*1.2f, v3.y*1.2f, v3.z*1.2f);
        }
        if (GUI.Button(new Rect(10, 120, 200, 50), " narrow "))
        {
            Vector3 v3 = transform.localScale;
            transform.localScale = new Vector3(v3.x/1.2f,v3.y/1.2f,v3.z/1.2f);
        }
       
    }
}                            
原网站

版权声明
本文为[Djc8 small yard farmer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091513177077.html

随机推荐