[ad_1]
I’ve obtained a 3D dice in a scene, and rotatable utilizing arrow keys. This is what it seems to be like, think about that the containers are left, proper, up, and down.
Unlike different questions, I’m not casting a ray forged on the dice immediately, although I’m attempting to do that to determine what face is going through the digital camera.
I would like to have the ability to determine what face is going through the digital camera, and when the arrows are what set off the motion 90′ in a given route.
Once I hear for the arrows transferring left or proper, I attempt to forged a Raycast immediately on the dice – however it would not appear to hit something or make a distinction if I take advantage of a 2D or 3D raycast. My scene is in 2D, however my dice is 3D. What am I doing unsuitable?
Here is my code:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public enum MCFace
{
None,
Up,
Down,
East,
West,
North,
South
}
public class CubeHandling : MonoBehaviour
{
personal void OnEnable()
{
TouchScreenManager.SignalButton += CheckCubeFace;
}
personal void OnDisable()
{
TouchScreenManager.SignalButton -= CheckCubeFace;
}
void CheckCubeFace(GameObject arrow)
{
if (arrow.title == "Left" || arrow.title == "Right")
{
// now forged one other raycast on the dice
var place = new Vector3(gameObject.remodel.place.x, gameObject.remodel.place.y, 0);
Ray ray = Camera.essential.ScreenPointToRay(gameObject.remodel.place);
Physics.Linecast(Camera.essential.remodel.place, place, out RaycastHit hit);
Debug.Log("the ray is: " + ray + " and the hit is " + hit);
var face = GetHitFace(hit);
Debug.Log(face);
}
}
public MCFace GetHitFace(RaycastHit hit)
{
Vector3 incomingVec = hit.regular - Vector3.up;
if (incomingVec == new Vector3(0, -1, -1))
return MCFace.South;
if (incomingVec == new Vector3(0, -1, 1))
return MCFace.North;
if (incomingVec == new Vector3(0, 0, 0))
return MCFace.Up;
if (incomingVec == new Vector3(1, 1, 1))
return MCFace.Down;
if (incomingVec == new Vector3(-1, -1, 0))
return MCFace.West;
if (incomingVec == new Vector3(1, -1, 0))
return MCFace.East;
return MCFace.None;
}
}
[ad_2]