Browse Source
Instantiates a scene object or prefab. Can optionally set a parent object and local position and rotation.master
chrisgregan
10 years ago
2 changed files with 75 additions and 0 deletions
@ -0,0 +1,63 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
// This command is called "Call Method" because a) it's more descriptive than Send Message and we're already have |
||||
// a Send Message command for sending messages to trigger block execution. |
||||
|
||||
[CommandInfo("Scripting", |
||||
"Spawn Object", |
||||
"Spawns a new object based on a reference to a scene or prefab game object.")] |
||||
[AddComponentMenu("")] |
||||
public class SpawnObject : Command |
||||
{ |
||||
[Tooltip("Game object to copy when spawning. Can be a scene object or a prefab.")] |
||||
public GameObject sourceObject; |
||||
|
||||
[Tooltip("Transform to use for position of newly spawned object.")] |
||||
public Transform parentTransform; |
||||
|
||||
[Tooltip("Local position of newly spawned object.")] |
||||
public Vector3 spawnPosition; |
||||
|
||||
[Tooltip("Local rotation of newly spawned object.")] |
||||
public Vector3 spawnRotation; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
if (sourceObject == null) |
||||
{ |
||||
Continue(); |
||||
return; |
||||
} |
||||
|
||||
GameObject newObject = GameObject.Instantiate(sourceObject); |
||||
if (parentTransform != null) |
||||
{ |
||||
newObject.transform.parent = parentTransform; |
||||
} |
||||
|
||||
newObject.transform.localPosition = spawnPosition; |
||||
newObject.transform.localRotation = Quaternion.Euler(spawnRotation); |
||||
|
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
if (sourceObject == null) |
||||
{ |
||||
return "Error: No source GameObject specified"; |
||||
} |
||||
|
||||
return sourceObject.name; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(235, 191, 217, 255); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: bb3e86f556e074b84af1cc7eb8f8e5e7 |
||||
timeCreated: 1431443741 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Loading…
Reference in new issue