I'm trying to get it so when I press the Fire1 button it will turn ON gravity for the "thingIHit" if it has the tag of "Enemy"
Raycasting works fine, but turning gravity on, on the rigidbody for the thingIHit does not.
ERROR: 'Rigidbody' is a type, which is not valid in the given context.
Raycasting works fine, but turning gravity on, on the rigidbody for the thingIHit does not.
ERROR: 'Rigidbody' is a type, which is not valid in the given context.
Code:
public class RayCastingScript : MonoBehaviour { void Update() { RaycastHit thingIHit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out thingIHit)) { if (Input.GetButtonDown("Fire1")) { if (thingIHit.collider.gameObject.tag == "Enemy") { thingIHit.transform.GetComponent(Rigidbody).useGravity = true; } } Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * thingIHit.distance, Color.yellow); Debug.Log("Did Hit"); } } }
Comment