- 자습서
- Space Shooter tutorial
- Creating hazards
Creating hazards
확인 완료한 버전: 5.1
-
난이도: 초급
Create an asteroid hazard to challenge the player.


Creating hazards
초급 Space Shooter tutorial
Please note that this project was developed for Unity version 4. It currently works, and has been checked, with Unity version 5.1. Please turn annotations on while watching the video, as we can add annotations to the videos when there are discrepancies between the recorded content and the current version of Unity.
Get the Upgrade Guide for Unity 5 here.
Please refer to the Official Q&A Page on the Forums for an Upgrade FAQ and to ask any questions.
RandomRotator
Code snippet
using UnityEngine;
using System.Collections;
public class RandomRotator : MonoBehaviour
{
public float tumble;
void Start ()
{
rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
}
}
var tumble : float;
function Start () : void {
rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
}
import UnityEngine
import System.Collections
public class RandomRotator(MonoBehaviour):
public tumble as single
private def Start():
rigidbody.angularVelocity = (Random.insideUnitSphere * tumble)
DestroyByContact
Code snippet
using UnityEngine;
using System.Collections;
public class DestroyByContact : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if (other.tag == "Boundary")
{
return;
}
Destroy(other.gameObject);
Destroy(gameObject);
}
}
function OnTriggerEnter(other : Collider)
{
if (other.tag == "Boundary")
{
return;
}
Destroy(other.gameObject);
Destroy(gameObject);
}
import UnityEngine
import System.Collections
public class DestroyByContact(MonoBehaviour):
private def OnTriggerEnter(other as Collider):
if other.tag == 'Boundary':
return
Destroy(other.gameObject)
Destroy(gameObject)
관련 자습서
- Rigidbodies (강좌)
- Colliders (강좌)
- Colliders as Triggers (강좌)
- Tags (강좌)
관련 문서
- Random (스크립팅 참고자료)
- Random.value (스크립팅 참고자료)
- Random.insideUnitSphere (스크립팅 참고자료)
- Adding Random Gameplay Elements (설명서)
- Rigidbody (설명서)
- Rigidbody (스크립팅 참고자료)
- Rigidbody.drag (스크립팅 참고자료)
- Rigidbody.angularDrag (스크립팅 참고자료)
- Capsule Collider (설명서)
- Collider (스크립팅 참고자료)
- Collider.OnTriggerEnter(Collider) (스크립팅 참고자료)
- Tags and Layers (설명서)
- GameObject.tag (스크립팅 참고자료)