- Home /
scripting help needed, load level?
i am making a game and i am having scripting problems i want to make it so when var bullet is touching var self level 2 loads
var bullet : Transform;
var self : Transform;
self = transform.rotation;
transform.rotation = Quaternion.identity;
function update (){
if (self){ Application.LoadLevel(2); }
}
//please post a full script
1) Please format your code!
2) Read up on OnCollision and use that to check for collisions
Answer by Steve Steven · Nov 21, 2012 at 06:01 PM
I suggest you to use Raycast.
Raycast is physics sensor we can call which goes from an origin, to a direction for a length, which if not assigned is Mathf.Infinity.
This physics sensor stops when get collision with any collider. In this way you don't need to instantiate this bullet as Transform.
so your script for raycast will be:
var origin : Vector3
var direction : Vector3;
var distance : float;
var hit : RaycastHit;
function ShootProjectile () {
if (Physics.Raycast (origin, direction, distance, hit)) {
//get collided
} else {
//no collision
}
}
if (hit.tag == "Tag") {
Application.LoadLevel (x);
}
If you need for more in depth detail, remember to check the Scripting Reference by Unity3d about Physics.Raycast
I got it up and runing without raycast but thanks for posting
Your answer
Follow this Question
Related Questions
Script in UNITY ??? 2 Answers
Bullet Fire script not working 1 Answer
How do i make an animation play on key press? 3 Answers
Convert this line of javascript to C# (easy) 1 Answer
i need some code suggestions 1 Answer