Search Unity

Balls falling constantly

Discussion in 'Scripting' started by gamecreator333, May 31, 2015.

  1. gamecreator333

    gamecreator333

    Joined:
    May 4, 2015
    Posts:
    21
    Hey everyone!
    I have a question I have had for awhile now. I am trying to make a script that makes balls fall from the top of my screen continuously and they keep falling until one of them touches the bottom of the screen and then the game over box pops up. I also have 4 different colors and I want it to pick a different color ball every time one of them falls. Thanks for the help!
     
  2. N0ught234

    N0ught234

    Joined:
    May 31, 2015
    Posts:
    7
    attach this to either the spheres or the other object that it collides with, then attach a RigidBody component to the sphere and check gravity is cheched on. the other object needs to have IsTrigger ticked on so that it can detect the other object.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ChangeScene : MonoBehaviour
    5. {
    6.     void OnCollisionEnter (Collision col)
    7.     {
    8.         if(col.gameObject.name == "FallingObject")
    9.         {
    10.             Application.LoadLevel ("GameOver");
    11.         }
    12.     }
    13. }
    When a collision between two Colliders occurs and if at least one of them has a Rigidbody attached, three collision messages are sent out to the objects attached to them. These events can be handled in scripting, and allow you to create unique behaviors with or without making use of the built-in NVIDIA PhysX engine.
     
  3. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    You could also use the shuriken particle system, where you can set the colour to vary etc. and also get collision messages out of the box :) Just another approach!
     
  4. gamecreator333

    gamecreator333

    Joined:
    May 4, 2015
    Posts:
    21
    Thanks for the help! I'll try that out.
     
  5. gamecreator333

    gamecreator333

    Joined:
    May 4, 2015
    Posts:
    21
    Thanks for the help! I'll look into that.
     
  6. gamecreator333

    gamecreator333

    Joined:
    May 4, 2015
    Posts:
    21
    Thanks for your help everyone!
    Everything is working fine.
    Except I just dont know how to make the infinite spawn script that spawns random balls infinitely.
     
  7. gamecreator333

    gamecreator333

    Joined:
    May 4, 2015
    Posts:
    21
    Any suggestions?
     
  8. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    have a look at the "Invoke(...)" function
     
    gamecreator333 likes this.
  9. gamecreator333

    gamecreator333

    Joined:
    May 4, 2015
    Posts:
    21
    Just searched it up. It's just what I was looking for. Thanks!
     
  10. chand55155

    chand55155

    Joined:
    Jun 14, 2018
    Posts:
    1
    Hey brother, I am trying to work on something similar, I was wondering if you can share your script of balls falling with different color?