Raycast to Terrain (Conditional Statements)

I have been trying to get my helicopter’s raycast line to collide with the terrain so that when the line collides with the terrain, something happens. For now I just put print for testing/debugging purposes.

I do not have a lot of experience with this Ray-casting business. What am I doing wrong?

Here is my code:

#pragma strict

public var Player : GameObject;
public var Follow : GameObject;
public var terrain : Terrain;    

 

	function Update () {
	
	var hit : RaycastHit;
 	 Debug.DrawRay(transform.position, transform.up * 3, Color.red);
 	 
 	 
    if(Physics.Raycast(transform.position, transform.up, hit, 3)) {
    if(hit.collider.gameObject == terrain){  
    
    print("You hit the Terrain.");
    
    }
    }
    }

I don’t understand how the Javascript side works, but it looks like you have not assigned your terrain variable.

In C# I would have to do something like:

GameObject Terrain = GameObject.Find(“Terrain”);

Right now it appears that your code is looking for a gameobject that you have called “terrain” but it still does not know if you want a specific gameobject called Terrain.