I have a roulette wheel, I want to make it spin dynamically, it will be on a big touch screen, and it would be fun to make it spin like you’re grabbing it. I was trying to just do some basic testing, and I can’t even get it to spin at all lol
I gave it a rigidbody2D and a circle collider, here is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WheelSpin : MonoBehaviour
{
public Camera camera;
public RaycastHit hit;
public Ray ray;
private void Update()
{
if (Input.GetMouseButton(0))
{
ray = new Ray();
if (Physics.Raycast(ray, out hit))
{
print("Almost");
var objectHit = hit.transform;
if (objectHit.CompareTag("Wheel"))
{
objectHit.GetComponent<Rigidbody2D>().AddTorque(5000);
}
}
}
}
}
I was just testing before I make it actually spin, but it doesn’t even seem to be registering the collision. I put 3 prints in, one on mouse click, which prints just fine, one after Physics.Raycast, which doesn’t seem to register at all…
Sorry if this is a noob question, raycasts always give me a headache… Also, this wheel is on the canvas.
Edit: Idk why I deleted it, but I changed the ray = new ray to Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
but it still isn’t registering anything.