Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Transform prefab;
void OnTriggerEnter() {
Instantiate(prefab);
}
}
using System.Collections;
public class example : MonoBehaviour {
public Transform prefab;
void OnTriggerEnter() {
Instantiate(prefab);
}
}
Но мне непонятно как объяснить "prefab"у что я хочу запилить на сцену
И еще: как потом его контролировать? Можно на него повесить скрипт отдельный?
////////////////////////////////////////////////////////////////////////////////////////////
Синтаксис:
Используется csharp
// Require the rocket to be a rigidbody.
// This way we the user can not assign a prefab without rigidbody
var rocket : Rigidbody;
var speed = 10.0;
function FireRocket () {
var rocketClone : Rigidbody = Instantiate(rocket, transform.position, transform.rotation);
rocketClone.velocity = transform.forward * speed;
// You can also acccess other components / scripts of the clone
rocketClone.GetComponent(MyRocketScript).DoSomething();
}
// Calls the fire method when holding down ctrl or mouse
function Update () {
if (Input.GetButtonDown("Fire1")) {
FireRocket();
}
}
// This way we the user can not assign a prefab without rigidbody
var rocket : Rigidbody;
var speed = 10.0;
function FireRocket () {
var rocketClone : Rigidbody = Instantiate(rocket, transform.position, transform.rotation);
rocketClone.velocity = transform.forward * speed;
// You can also acccess other components / scripts of the clone
rocketClone.GetComponent(MyRocketScript).DoSomething();
}
// Calls the fire method when holding down ctrl or mouse
function Update () {
if (Input.GetButtonDown("Fire1")) {
FireRocket();
}
}
Так. Наткнулся еще на это. "rocket" это название префаба? И еще
Синтаксис:
Используется csharp
rocketClone.GetComponent(MyRocketScript).DoSomething();
можно задействовать не функцию, а скрипт целиком?