public void createGem(Vector3 initialPos = default(Vector3), float speed = 5) { GameObject gemType = gems_types[0]; // gem GameObject gem = (GameObject)Instantiate(gemType, transform.position + initialPos, Quaternion.identity); SetVelocity velocity = gem.AddComponent <SetVelocity>(); velocity.speed = speed; gem.transform.parent = GemsParentArray.transform; gem.tag = "Coins"; }
public void createSmallPlane(Vector3 initialPos = default(Vector3), float speed = 5) { GameObject planeType = planes_types[0]; // small plane GameObject plane = (GameObject)Instantiate(planeType, transform.position + initialPos, Quaternion.identity); SetVelocity velocity = plane.AddComponent <SetVelocity>(); velocity.speed = speed; plane.transform.parent = PlanesParentArray.transform; plane.transform.GetChild(0).tag = "Planes"; }
public void createAirBalloon(Vector3 initialPos = default(Vector3), float speed = 5) { GameObject planeType = planes_types[2]; // war plane GameObject plane = (GameObject)Instantiate(planeType, transform.position + initialPos, Quaternion.identity); SetVelocity velocity = plane.AddComponent <SetVelocity>(); velocity.speed = speed; plane.transform.parent = PlanesParentArray.transform; plane.tag = "Airballoon"; }
public void releaseObject() { int random = (int)Mathf.Floor(Random.Range(0, planes_types.Length)); GameObject planeType = planes_types [random]; GameObject plane = (GameObject)Instantiate(planeType, transform.position + new Vector3(0, 1, 0), Quaternion.identity); SetVelocity velocity = plane.AddComponent <SetVelocity>(); switch (random) { case 0: velocity.speed = 30; break; case 1: velocity.speed = 20; break; case 2: velocity.speed = 5; break; default: break; } plane.transform.parent = PlanesParentArray.transform; if (random != 2) { plane.transform.GetChild(0).tag = "Planes"; } else { plane.transform.GetChild(0).tag = "Airballoon"; } Vector3 randomPosition = new Vector3(Random.Range(-distanceFromCenter, distanceFromCenter), 0, 0); //transform.rotation = Quaternion.AngleAxis(Random.Range (0, 360), Vector3.up); plane.transform.position = this.gameObject.transform.position + randomPosition; }
public void ApplyVelocity(GameObject obj, float testDifficulty) { SetVelocity sv = obj.GetComponent <SetVelocity>(); float currentTime = testDifficulty == 0 ? Time.timeSinceLevelLoad : testDifficulty; Vector2 hVelocity = UnityEngine.Random.Range(minHorizontalVelocity.Evaluate(currentTime), maxHorizontalVelocity.Evaluate(currentTime)) * (flipHorizontal ? -1.0F : 1.0F) * transform.right; Vector2 vVelocity = UnityEngine.Random.Range(minVerticalVelocity.Evaluate(currentTime), maxVerticalVelocity.Evaluate(currentTime)) * (flipVertical ? -1.0F : 1.0F) * transform.up; Vector3 velocity = hVelocity + vVelocity; if (sv != null) { sv.initialVelocity = velocity; } if (obj.GetComponent <SetRotation>() != null) { Vector2 dir = velocity - obj.transform.position; float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; obj.transform.rotation = Quaternion.AngleAxis(angle - 90.0F, Vector3.forward); } }