Saturday, 28 February 2015

Interactivity - Asteroids


  • create new game object, name it asteroid, set to origin then move it to z 8 
  • select asteroid model from model folder and drag onto asteroid in the hierarchy so it is a child of the game object 
  • add a ridigidbody, turn gravity off and add a capsule collider, scale to the size of the asteroid 
  • you can make the asteroid spin by using the code bellow how ever for my game i did not need to use this 
  • add a new script to the asteroid component called destroy by contact 
  • write this code 
  • then go back into unity, go to the bounday object int he hierarchy and tag it as bounday 
  • open the destroy by contact script again write 

  • save and go back to unit, click on the asteroid prefab and in the inspector  where the destroy by contact script is add the explosion prefebs to it the add the mover script on to the asteroid game object 
  •  then add the mover script on to the asteroid game object and set the speed to -5  
  • go to the player game object and tag it as player 
  • drag the asteroid from the hierarchy into the pre fabs folder and then delete the asteroid from the hierarchy 

No comments:

Post a Comment