• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Grimlock257 · Nov 13, 2010 at 12:39 AM · loadleveltornado-twins

Load Next Level when all turrets are dead

I really need some help. I need my Game to load level 2 when all the turrets are dead. Im followed the Tornado Twins Tutorials and I finished them. Im using Java Script, I have 28 Turrets, when they are all dead i need it to Load Level 2 (Application.LoadLevel(3)). Please help me make a simple script that can do, also, i need this for my other levels.

//Movment and Target var LookAtTarget:Transform; var damp = 1.7; var ememy : Transform;

//Shooting var bullitPrefab:Transform; var savedTime=0; var curShoot = true;

function Update () { if(LookAtTarget) {
if ( Vector3.Distance( ememy.position, transform.position ) < 18 )

      var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);

      transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);

      if(curShoot)
      {     
             var seconds : int = Time.time;
             var oddeven = (seconds % 2);

             if(oddeven)
             {     
                    Shoot(seconds);
             }
      } 

} }

function Shoot(seconds) {
if ( Vector3.Distance( ememy.position, transform.position ) < 15 ) { if(seconds!=savedTime) {
var bullit = Instantiate(bullitPrefab ,transform.Find("SpawnPoint").transform.position , Quaternion.identity); bullit.gameObject.tag = "ememyProjectile"; bullit.rigidbody.AddForce(transform.forward 1600);
bullit.rigidbody.AddForce(transform.up
45); savedTime=seconds; }
} }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChimpKing · Nov 13, 2010 at 02:47 AM 1
Share

"Please help me make a simple script that can do" You should probably learn to script yourself. You can't have people making everything for you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BinaryCaveman · Nov 13, 2010 at 01:02 AM

Do you have a counter variable that stores the number of turrets that are alive? If so, this script could work: (javascript)

var turrets : int; // This stores the number of turrets that are alive. // You can input initial number of turrets for this script in the editor

function killTurret() // Call this function to reduce the number of living turrets { turrets--;

   // This checks if this was the last turret to kill, if so, it loads another scene
   if (turrets &gt;= 0)
   {
        Application.LoadLevel(3);
   }

}

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Grimlock257 · Nov 13, 2010 at 12:37 PM 0
Share

Integer dose't work properly, Plus it didt work at all. And no i dont have any other Counter Variable. How could i fix this? By the Way the 28 Turrets are in a Game Object called Enemy and in that is the 28 Turrets

avatar image BinaryCaveman · Nov 13, 2010 at 08:50 PM 0
Share

Sorry - I meant 'int' ins$$anonymous$$d of 'Integer'. I changed the code. The function killTurret() is supposed to be called when a turret is killed. Since you don't have a counter variable, this could be it. You could place this script on the Enemy GameObject, and have a turret (child of enemy) call this script in its parent GameObject.

avatar image Grimlock257 · Nov 14, 2010 at 08:39 PM 0
Share

I did that, it still wont work. Please Help me

avatar image BinaryCaveman · Nov 14, 2010 at 11:55 PM 0
Share

Could you clearly state everything that you did? Otherwise, I will not be able to help you.

avatar image Grimlock257 · Nov 15, 2010 at 09:37 PM 0
Share

Well I'm not the best at scripting, I know I'm repeating myself but I have A I made a Empty Game-object and named it Enemy, in the that is my 28 Turrets, Turret is a game object containing the Legs/Tripod and Tophalf containing A barrel and a head. I have no Counter Variables or any other, the only script I have to do with Turrets is Turret Control a script that controls the Turret... All I need is a simple JavaScript to load level 3 when 28 turrets have been deleted... Please Help, I'm new to JavaScript as well - more like new to Unity.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Delays when move to another scene 1 Answer

Next lvl code help 1 Answer

level load problem 2 Answers

loading a heavy level fast 2 Answers

Restart Current Level 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges