So I will start off by saying that I am very new to this, have been using Gamer to developer to try to get a grasp on this. Somewhere a long the way, I had to mess up doing this script to make my game object execute if it hits another object. So this is what I got so far, please let me know where I messed up.
/// <summary>
/// This script is attached to the Blaster projectile and it
/// governs the behaviour of the projectile.
///
/// </summary>
public class BlasterScript : MonoBehaviour {
//Variables Start
//A quick reference.
private Transform myTransform;
//The projectiles flight speed.
private float projectileSpeed = 10;
//Prevent the projectile from causing
//further harm once it has hit something.
private bool expended = false;
//A ray projected in front of the projectile
//to see if it will hit a recognisable collider.
private RaycastHit hit;
//The range of that ray.
private float range = 1.5f;
//Variables End
void Start ()
{
myTransform = transform;
}
// Update is called once per frame
void Update ()
{
//Translate the projectile in the up direction the pointed
//end of the projectile.
myTransform.Translate (Vector3.up * projectileSpeed * Time.deltaTime);
//If the ray hits something then execute this code.
if(Physics.Raycast(myTransform.position.myTransform.up. out hit. range) &&
expended == false)
(
//If the collider has the tag of Floor then..
if(hit.transform.tag == "Floor")
(
expended = true;
//Make the projectile become invisible.
myTransform.renderer.enabled = false;
//Turn off the light. The halo will also disappear.
myTransform.light.enabled = false;
)
)