Created
March 7, 2020 06:10
-
-
Save SatoshiRobatoFujimoto/d3224756f1e3a7cce880b36905cb4d13 to your computer and use it in GitHub Desktop.
ObjectsManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Microsoft.MixedReality.Toolkit.UI; | |
public class ObjectsManager : MonoBehaviour | |
{ | |
public GameObject cube; | |
public void OnButtonClicked() | |
{ | |
GameObject tmp = Instantiate(cube); | |
var size = tmp.GetComponent<BoundingBox>().TargetBounds.size; | |
var pos = Camera.main.transform.TransformPoint(0.0f, 0.0f, size.z + 0.8f); | |
var dir = Quaternion.LookRotation(pos - Camera.main.transform.position, Vector3.up); | |
dir.z = 0; | |
dir.x = 0; | |
tmp.transform.position = Camera.main.transform.position + dir * new Vector3(0.0f, 0.0f, size.z + 0.8f); | |
var dif = Camera.main.transform.position - tmp.transform.position; | |
tmp.transform.rotation = Quaternion.LookRotation(new Vector3(dif.x, 0, dif.z)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment