Skip to content

Instantly share code, notes, and snippets.

@SatoshiRobatoFujimoto
Created June 13, 2018 11:45
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/967eb35262d2a5e19226aec200fffaca to your computer and use it in GitHub Desktop.
Save SatoshiRobatoFujimoto/967eb35262d2a5e19226aec200fffaca to your computer and use it in GitHub Desktop.
HoloLens オブジェクト投げるスクリプト
using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity.InputModule;
using UnityEngine;
public class ThrowingObject : MonoBehaviour, IInputClickHandler
{
public float thrust;
public GameObject obj;
// Use this for initialization
void Start()
{
InputManager.Instance.AddGlobalListener(gameObject);
}
public void OnInputClicked(InputClickedEventData eventData)
{
GameObject clone = GameObject.Instantiate(obj);
clone.transform.position = Camera.main.transform.TransformPoint(0.0f, 0.1f, 0.0f);
Rigidbody rb = clone.GetComponent<Rigidbody>();
rb.AddForce(Camera.main.transform.forward * thrust);
rb.useGravity = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment