hello, i need help on the raycast for the functionally for the nursing simulator. I’m a beginner programmer and i’m trying figure out how to make it work for our game.
You have not said what isn’t working, and you haven’t used CODE tags (its the # button in the form)
I’m working the raycast to point to the patient’s body or at least build functionality on it. I want use a sphere collider to make the body move and Building the raycast would trigger a event or make the patient move or at flash the body of it. Like i said, i’m trying to build a raycast script for nursing simulation where the patient got injured .
using UnityEngine; using System.Collections;
public class Raycast : MonoBehaviour {
public GameObject Spherecollider;
private RaycastHit hit;
float distance = 25.0f;
public float power = 25f;
// Use this for initialization
void Start (){
}
// Update is called once per frame
void Update () {
//Left mouse buttton
if (Input.GetMouseButtonDown(0))
{
Ray rayOrigin = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if(Physics.Raycast(rayOrigin, out hitInfo, distance))
{ Debug.Log (“Casted a Ray”);
Debug.DrawLine(rayOrigin.direction, hitInfo.point);
if (hitInfo.rigidbody != null)
{
//Instantiate(GameObject, hitinfo.point, transform.rotation);
//Call out the hit information, Rigidbody, addforceposition menu, direction position of the force should be and add the variable hitInfo.rigidbody.AddForceAtPosition(rayOrigin.dir ection * power, hitInfo.point);
//Call Hit info, Transformation, Gameobject,render, material, color } } } } }
I’ve apologize if i didn’t do it right before, Can you look at now where it make more sense?