UnityのSteamVRについているサンプルシーンの中にある
弓で打って風船が出るスクリプトを改造したいのですが、何処を編集するのかわかりません。
やりたいこと
青く丸い所が1つのプレハブしか入らず、他のプレハブオブジェクトもアタッチ出来るように枠を出せるようにしたいです。
balloon
1using UnityEngine; 2using System.Collections; 3 4namespace Valve.VR.InteractionSystem 5{ 6 //------------------------------------------------------------------------- 7 public class BalloonSpawner : MonoBehaviour 8 { 9 public float minSpawnTime = 5f; 10 public float maxSpawnTime = 15f; 11 private float nextSpawnTime; 12 public GameObject balloonPrefab; 13 14 public bool autoSpawn = true; 15 public bool spawnAtStartup = true; 16 17 public bool playSounds = true; 18 public SoundPlayOneshot inflateSound; 19 public SoundPlayOneshot stretchSound; 20 21 public bool sendSpawnMessageToParent = false; 22 23 public float scale = 1f; 24 25 public Transform spawnDirectionTransform; 26 public float spawnForce; 27 28 public bool attachBalloon = false; 29 30 public Balloon.BalloonColor color = Balloon.BalloonColor.Random; 31 32 33 //------------------------------------------------- 34 void Start() 35 { 36 if ( balloonPrefab == null ) 37 { 38 return; 39 } 40 41 if ( autoSpawn && spawnAtStartup ) 42 { 43 SpawnBalloon( color ); 44 nextSpawnTime = Random.Range( minSpawnTime, maxSpawnTime ) + Time.time; 45 } 46 } 47 48 49 //------------------------------------------------- 50 void Update() 51 { 52 if ( balloonPrefab == null ) 53 { 54 return; 55 } 56 57 if ( ( Time.time > nextSpawnTime ) && autoSpawn ) 58 { 59 SpawnBalloon( color ); 60 nextSpawnTime = Random.Range( minSpawnTime, maxSpawnTime ) + Time.time; 61 } 62 } 63 64 65 //------------------------------------------------- 66 public GameObject SpawnBalloon( Balloon.BalloonColor color = Balloon.BalloonColor.Red ) 67 { 68 if ( balloonPrefab == null ) 69 { 70 return null; 71 } 72 GameObject balloon = Instantiate( balloonPrefab, transform.position, transform.rotation ) as GameObject; 73 balloon.transform.localScale = new Vector3( scale, scale, scale ); 74 if ( attachBalloon ) 75 { 76 balloon.transform.parent = transform; 77 } 78 79 if ( sendSpawnMessageToParent ) 80 { 81 if ( transform.parent != null ) 82 { 83 transform.parent.SendMessage( "OnBalloonSpawned", balloon, SendMessageOptions.DontRequireReceiver ); 84 } 85 } 86 87 if ( playSounds ) 88 { 89 if ( inflateSound != null ) 90 { 91 inflateSound.Play(); 92 } 93 if ( stretchSound != null ) 94 { 95 stretchSound.Play(); 96 } 97 } 98 balloon.GetComponentInChildren<Balloon>().SetColor( color ); 99 if ( spawnDirectionTransform != null ) 100 { 101 balloon.GetComponentInChildren<Rigidbody>().AddForce( spawnDirectionTransform.forward * spawnForce ); 102 } 103 104 return balloon; 105 } 106 107 108 //------------------------------------------------- 109 public void SpawnBalloonFromEvent( int color ) 110 { 111 // Copy of SpawnBalloon using int because we can't pass in enums through the event system 112 SpawnBalloon( (Balloon.BalloonColor)color ); 113 } 114 }
回答1件
あなたの回答
tips
プレビュー