linecast parameters


I am having problems getting linecast to work. I want to test for a line collision
and how do I set the target paramter?

public Transform target;

target = GameObject.Find(“Wall”).transform;

if (Physics.Linecast(transform.position, target.position, out hit))
//error as doesnt understand target

Yes I fixed that but what is target? I have to manually assign a target to cast to .
LineCast then works like a trip wire as it is anchored at 2 fixed points .
I had it placed on a bullet and that is why it isnt making sense.

Linecast simply take two Vector3, a start and an end. The doc uses two gameobject’s transform because it’s convenient, as you can edit them visually with their gizmos. But this would work to :

if( Physics.Linecast(new Vector3(0, 0, 0), new Vector3(10, 0, 0), out hit) )

The error in your code probably was a null exception. Wich is odd, because that would mean that “Wall” wasn’t found, in which case Find(“Wall”).transform would have raised an exception, or that you destroy the wall between the Find and the Linecast.