Answer the question
In order to leave comments, you need to log in
How to cast a raycast from an object?
I create a crane in unity, but I need to capture an object, but I need to throw a raycast from the crane, here is the code:
using UnityEngine;
using System.Collections;
using System;
public class pickupper : MonoBehaviour {
void Start()
{
if(Input.GetMouseButtonDown(1));
{
RaycastHit hit;
Vector3 fwd = Camera.main.transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(Camera.main.transform.position, fwd, out hit, 100.0f))
{
if (hit.collider.GetComponent<Rigidbody> () != null)
{
//Что будет делать...
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
You cast a raycast in order to understand what object you can intersect with, moving in the direction of the beam at a distance d (in your case - 100).
After you understand what you are intersecting with, you must understand whether this item can be grabbed or not.
If the object can be grabbed, then you attach it to the crane hook with a gin (if you have physics).
In CSS, the :hover event fires only on child elements, you need to use jQuery there, it doesn't matter
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question