public void onSpawn(Vector3 position) { GameObject JunkInstance; JunkInstance = Instantiate(ballPrefab); JunkInstance.transform.position = position; JunkInstance.GetComponent <Rigidbody2D>().AddForce(new Vector2(10f * 100, 10f * 100)); }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { GameObject JunkInstance; JunkInstance = Instantiate(myScript); if (!JunkInstance.GetComponent <mySpawner>().isActive()) { JunkInstance.GetComponent <mySpawner>().setActive(true); } } }
public void SpawnObject() { float arrayLen = myGameobject.Length; int i = (int)Random.Range(0f, arrayLen); GameObject JunkInstance; JunkInstance = Instantiate(myGameobject[i]); JunkInstance.transform.SetParent(position, false); // JunkInstance.transform = position; JunkInstance.GetComponent <Rigidbody2D>().gravityScale = gravityScale; JunkInstance.GetComponent <Rigidbody2D>().AddForce(spawnForce); if (incrementX && Mathf.Abs(spawnForce.x) <= 1000) { spawnForce.x += incrementXBy; } if (incrementY && Mathf.Abs(spawnForce.y) <= 1000) { spawnForce.y += incrementYBy; } if (!isActive()) { CancelInvoke("SpawnObject"); } }