CS185c
Chris Pollett
Apr 24, 2019

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyInputController : MonoBehaviour
{
// Update is called once per frame
void Update()
{
ButtonTest();
}
private void ButtonTest()
{
string msg = null;
if (Input.GetButtonDown("Fire1")) {
msg = "Fire1 down";
}
if (Input.GetButtonUp("Fire1")) {
msg = "Fire1 up";
}
if (msg != null) {
Debug.Log("Input: " + msg);
}
}
}
04-24 11:43:49.890 8249 8264 I Unity : 04-24 11:44:15.932 8249 8264 I Unity : Input: Fire1 down 04-24 11:44:15.932 8249 8264 I Unity : 04-24 11:44:15.932 8249 8264 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 48) 04-24 11:44:15.932 8249 8264 I Unity : 04-24 11:44:16.083 8249 8264 I Unity : Input: Fire1 up 04-24 11:44:16.083 8249 8264 I Unity : 04-24 11:44:16.083 8249 8264 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 48) 04-24 11:44:16.083 8249 8264 I Unity :
OVRInput.IsControllerConnected(OVRInput.Controller.RTrackedRemote);
//true if trigger pressed OVRInput.Get(OVRInput.Button.One); // returns a Vector2 of the primary touchpad position OVRInput.Get(OVRInput.Axes2D.PrimaryTouchPad);
private void ButtonTest()
{
string msg = null;
if (Input.GetButtonDown("Fire1")) {
//OVRInput.GetDown(OVRInput.Button.One) also works
msg = "Fire1 down";
NewBalloon();
}
if (Input.GetButtonUp("Fire1")) {
//OVRInput.GetUp(OVRInput.Button.One) also works
msg = "Fire1 up";
ReleaseButton();
}
if (msg != null) {
Debug.Log("Input: " + msg);
}
}
public GameObject balloonPrefab; //remember to drag the prefab over to this in My Input Controller public float floatStrength = 20f;and another private variable to hold the current instance of the balloon:
private GameObject balloon;
private void NewBalloon()
{
balloon = Instantiate(balloonPrefab);
}
private void ReleaseButton()
{
// observe how we refer to a sub component.
balloon.GetComponent<Rigidbody>().AddForce(Vector3.up * floatStrength);
balloon = null; /* Setting Balloon only gets rid of our reference,
not the object. To actually remove an object use:
Destroy (someGameObject); */
}
public AudioSource missile;
and make sure in OVRCameraRig's Inspector - My Input Controller script we drag our Audio Source over to fill in the value for the Missle field.
if (Input.GetButtonDown("Fire1")) {
msg = "Fire1 down";
NewBalloon();
missile.Play();
}
public GameObject myObject;
then referred to its AudioSource with myObject.GetComponent<AudioSource>()