Something like Rigidbody may seem trivial for some of you, but for myself at the moment, it’s a nightmare. I’m attempting to code a gameObject (named “barrel”) in such a way that it is able to have a force applied via a Raycast.
Ray ray = Camera.main.ScreenPointToRay
(new Vector3(x,y,0));
RaycastHit hit=new RaycastHit();
if (Physics.Raycast(ray,out hit)){
if(hit.collider.gameObject.name=="barrel"){
RaycastHit.Rigidbody.AddForceAtPosition(Vector3.Raycast.direction*10.0f);
Debug.Log("Barrel was destroyed.");
This is how far I’ve gotten just now, with line 8 being what I’m confused about.
Cheers for any help put forth! For any backstory, I’ve only just started using Unity3d at university, and only just started coding C#. I’ve checked the scripting reference, but just cant seem to gain any insight into my problem.