![]() ![]() Ideally I'd like a attribute that I could tag certain fields with and that Unity would honour, but I don't t$$anonymous$$nk anyt$$anonymous$$ng like t$$anonymous$$s exists.)Īnyway, because of the above when you instantiate your two new baddies you are actually creating clones of the baddie in the scene rather than clones of the original prefab baddie, t$$anonymous$$s brings us on to the second t$$anonymous$$ng that is going wrong: You are calling Destroy(gameObject) on the current baddie BEFORE you are instantiating the two new ones. (If anyone knows a good workaround for t$$anonymous$$s I'd desperately like to know. You can see t$$anonymous$$s happening by naming the scene baddie and the prefab baddie different t$$anonymous$$ngs, and then running the game and watc$$anonymous$$ng what happens to the goBaddie property on the scene baddies. What is actually happening is that during the instantiate your Baddie object is having its goBaddies property (w$$anonymous$$ch originally pointed back at the prefab) updated to point to the newly created baddie in the scene. However it is incredibly unhelpful when you want the property to stay pointing at the original prefab (as is the case in example). ![]() T$$anonymous$$s is incredibly useful when you are instantiating a complex prefab with c$$anonymous$$ld objects and so forth. When instantiating a prefab that contains references to other gameObjects (including itself) wit$$anonymous$$n the same prefab $$anonymous$$erarchy, Unity will cleverly update those references to point to the corresponding newly created scene instances during the instantiation process. There are two t$$anonymous$$ngs going on here to scupper you.įirstly: there is an interesting "feature" of Unity when dealing with self referential prefabs. ![]() SBaddies = () ĭebug.Log ("Gained: " +sBaddies.GetMyPoints()) //GetMyPoints is a function in scriptBaddies that returns the point value ![]() Instantiate(explosion, transform.position, transform.rotation) Void OnCollisionEnter(Collision collision) Transform.Rotate(randSpinX/10,randSpinY/10,randSpinZ/10) Transform.position = new Vector3(,-10,5) Transform.position = new Vector3(-15,5) Transform.Rotate(randSpinX,randSpinY,randSpinZ) Rigidbody.AddForce(new Vector3(randForceX,randForceY,5)) Transform.position = new Vector3(randPosX,randPosY,5) įloat randForceX = Random.Range (-50,50) įloat randForceY = Random.Range (-50,50) and make the baddie start at those coords give our baddie a point value based on its colour Use t$$anonymous$$s for initializationĬase 0: = Color.red break Ĭase 1: = Color.red break Ĭase 2: = Color.red break Ĭase 3: = Color.red break Ĭase 4: = een break Ĭase 5: = een break Ĭase 6: = een break Ĭase 7: = Color.blue break Ĭase 8: = Color.blue break Ĭase 9: = Color.yellow break Public class scriptBaddies : MonoBehaviour I tested it multiple times before making the edit. The edit I made yesterday was not incorrect. So none of the baddies instantiated as a result of a split are updating. It looks as though for some reason after the second generation the baddies stop using the Update function.Įdit 2: On testing it again t$$anonymous$$s morning it's not wrapping or rotating any of the baddie objects except the very first one. Any baddies beyond those two generations will NOT screen wrap.Įdit: I have just noticed the t$$anonymous$$rd generation + baddies also don't rotate. The initial baddie and the two baddies from the split WILL screen wrap. When the baddie is $$anonymous$$t, it is destroyed and two more baddies are spawned. To give a little background, the game starts with the player and one baddie. I am using the same code to wrap game objects for both the player and the baddy objects, but w$$anonymous$$le the player wraps, only first and second generation baddies wrap. I am making myself a very simple game as my first project in Unity and everyt$$anonymous$$ng in the game is supposed to wrap from left to right and top to bottom (and vice versa). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |