i created laser by follow this steps but when it fire it go infinitive how to detect collision pls help
Model of Laser (Capsule is what worked for me, scale it by One axis until it looks like a laser)
Texture the model - Create a new Material, then assign the Default color to Red, then drag it onto the Laser model
Create a prefab with the Model - Create a new prefab, then drag the Laser model onto it.
Add script that makes it go forward: New JavaScript -> add these lines:
function Update() {
transform.Translate(Vector3.forward * Time.deltaTime);
}
-
add that script to your Prefab
-
when fire button press some action occur and fire laser
Horrible phrasing but if I understand correctly you want it to detect collision and do something on collision.
If you want to create a ray from point A to point B and want to have it stop at point B, then what follows, is the wrong method.
Not sure if it is Destroy(this) or Destroy(GameObject), don’t have Unity in front of me right now but this should work to some degree.
Suggest you go look at http://docs.unity3d.com/Documentation/ScriptReference/index.html for all your scripting needs - find the thing you’re working on and look at the functions that gameobject/whatever has.
private var shouldDie: float = false;
function Update(){
transform.Translate(Vector3.forward * Time.deltaTime);
if(shouldDie){
//Add explosion prefab, sounds, etc here - you may need to create additional gameobjects because Destroy removes all children and scripts - trigger the sfx in a separate gameObject
Destroy(this);
}
}
function onCollisionEnter(collidedWith: Collider){
shouldDie = true;
}