当前位置: 抚州教学网 >> 程序开发 >> Unity3D开发 >>

Unity教程 创建危险

返回Unity教程-太空设计游戏教程


Unity3D教程创建一个小行星危险来挑战玩家。


请注意,此项目是为Unity版本4开发的。它目前正在运行,并已通过Unity版本5.1进行检查。请在观看视频时开启注释,因为当录制的内容与当前版本的Unity之间存在差异时,我们可以向视频添加注释。 


RandomRotator

C#

using UnityEngine;
using System.Collections;

public class RandomRotator : MonoBehaviour
{
    public float tumble;

    void Start ()
    {
        rigidbody.angularVelocity = Random.insideUnitSphere * tumble; 
    }
}

JS

var tumble : float;

function Start () : void {
    rigidbody.angularVelocity = Random.insideUnitSphere * tumble; 
}

Boo

import UnityEngine
import System.Collections

public class RandomRotator(MonoBehaviour):
    public tumble as single

    private def Start():
        rigidbody.angularVelocity = (Random.insideUnitSphere * tumble)

DestroyByContact

C#

using UnityEngine;
using System.Collections;

public class DestroyByContact : MonoBehaviour
{
    void OnTriggerEnter(Collider other) 
    {
        if (other.tag == "Boundary")
        {
            return;
        }
        Destroy(other.gameObject);
        Destroy(gameObject);
    }
}

JS

function OnTriggerEnter(other : Collider) 
{
    if (other.tag == "Boundary")
    {
        return;
    }
    Destroy(other.gameObject);
    Destroy(gameObject);
}

Boo

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)


返回Unity教程-太空设计游戏教程

猜你喜欢