public void DiskFly(GameObject disk, float angle, float power) { int direction = (disk.transform.position.x > 0) ? -1 : 1; flyAction = DiskFlyPhysicsAction.GetSSAction(disk, angle, power); this.RunAction(disk, flyAction, this); }
public static DiskFlyPhysicsAction GetSSAction(GameObject disk, float angle, float power) { ConstantForce constantForce = disk.GetComponent <ConstantForce>(); if (constantForce) { constantForce.enabled = true; constantForce.force = new Vector3(0, -power, 0); } else { disk.AddComponent <Rigidbody>().useGravity = false; disk.AddComponent <ConstantForce>().force = new Vector3(0, -power, 0); } float x = Random.Range(-15f, 15f), y = Random.Range(15f, 20f), z = Random.Range(5f, 10f); disk.transform.position = new Vector3(x, y, z); DiskFlyPhysicsAction action = CreateInstance <DiskFlyPhysicsAction>(); action.speed = Quaternion.Euler(new Vector3(0, 0, angle)) * Vector3.right * power; return(action); }