- Home /
Create GameObject On Click Not Working
Can you guys please help with my code. I have made this code which is made so that when the menu button on the VIVE is clicked, a new game object is spawned. For some reason, even though there are no errors, the code does not work. Please help me fix this code.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CreateBallOnPress : MonoBehaviour
{
public GameObject Ball;
public Vector3 BallValues;
private Valve.VR.EVRButtonId menuButton = Valve.VR.EVRButtonId.k_EButton_ApplicationMenu;
private SteamVR_Controller.Device controller { get { return SteamVR_Controller.Input((int)trackedObj.index); } }
private SteamVR_TrackedObject trackedObj;
void Update()
{
Vector3 BallPosition = new Vector3(BallValues.x, BallValues.y, BallValues.z);
Quaternion BallRotation = Quaternion.identity;
if (controller.GetPressDown(menuButton))
{
Instantiate(Ball, BallPosition, BallRotation);
}
}
}
Is Update even running? (script enabled, GO enabled etc.)?
Is it possible to log "Any$$anonymous$$ey" for the controller, so you can see what buttons are actually pressed?
Your answer
Follow this Question
Related Questions
node null reference 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
How to choose random spawn point and spawn within its limit? 0 Answers
Why doesn't my spawning code work? 2 Answers
How do I make a game object spawn and then stay and move up when mouse is cilcked? 1 Answer