Im fairly new to scripting and Im still learning the basics. I have a basic first person character controller, and some game objects in my scene. So far what i can do its run a round and cast a ray from my character. id like to be able to modify the object that the ray returns.
say if the tree i clicked on had a script with a “fallDown” function or somthing, is there a way i can call that from the ‘hit’ variable that my raycast returned into?
using UnityEngine;
using System.Collections;
public class AimScript : MonoBehaviour {[[
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
var ray = new Ray (transform.position, transform.forward);
Debug.DrawRay (ray.origin, ray.direction * 10, Color.red);//test
RaycastHit hit;
if(Input.GetButtonDown ("Fire1") && hit.distance <= 6)
{
// somthing like:
// if( hit has TreeScript component )
// run TreeScript's falldown function.
}
}
}
any help would be much appreciated.