Skip to content

Instantly share code, notes, and snippets.

@SatoshiRobatoFujimoto
Created March 7, 2020 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SatoshiRobatoFujimoto/d3224756f1e3a7cce880b36905cb4d13 to your computer and use it in GitHub Desktop.
Save SatoshiRobatoFujimoto/d3224756f1e3a7cce880b36905cb4d13 to your computer and use it in GitHub Desktop.
ObjectsManager.cs
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