public void GenerateDie(Vector3 point) { GameObject newDie = GameObject.Instantiate(originalDie); newDie.transform.parent = gameSetTransform; newDie.transform.localPosition = new Vector3(point.x - transform.position.x, startingHeight, point.z - transform.position.z); //newDie.transform.localScale = new Vector3(1.f, 1.f, 1.f); newDie.transform.localRotation = Random.rotation; //newDie.GetComponent<Renderer>().enabled = true; newDie.SetActive(true); dice.Add(newDie); Rigidbody rigidBody = newDie.GetComponent <Rigidbody>(); Vector3 torque; torque.x = Random.Range(-200, 200); torque.y = Random.Range(-200, 200); torque.z = Random.Range(-200, 200); rigidBody.AddTorque(torque); DieController dieController = newDie.GetComponent <DieController>(); dieController.OnCreateDie(); dieController.enabled = true; }
private void ThrowDice(Vector3 force) { for (int i = 0; i < Dice.Count; i++) { GameObject die = Dice[i]; DieController controller = die.GetComponent <DieController>(); controller.Throw(force); } State = States.Rolling; }
private void MakeDiceThrowable(object sender, EventArgs args) { for (int i = 0; i < Dice.Count; i++) { GameObject die = Dice[i]; DieController controller = die.GetComponent <DieController>(); controller.MakeThrowable(); } HideBatter(); State = States.WaitingForRoll; cameraController.FinishedMoving -= new GameCamera.CameraEventHandler(MakeDiceThrowable); }
private void Awake() { opsc = GetComponent <OperationSoundController>(); weaponController = GetComponent <WeaponController>(); opc = GetComponent <OperationController>(); skillController = GetComponent <SkillController>(); buffController = GetComponent <BuffController>(); combatController = GetComponent <CombatController>(); knockBackSystem = GetComponent <KnockStunSystem>(); dieController = GetComponent <DieController>(); iconController = GetComponent <IconController>(); cumulativeDataController = GetComponent <CumulativeDataController>(); rb = GetComponent <Rigidbody2D>(); anim = GetComponent <Animator>(); animController = new AnimatorOverrideController(anim.runtimeAnimatorController); _attack = new CommonAttackControl(this); anim.runtimeAnimatorController = animController; cycleAttackCount = data.cycleAttackCount; nextAttackResetTime = 0; attackComboCount = 0; ReBorn(); }
// Update is called once per frame void Update() { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) { TouchEvent(); } if (Input.GetMouseButtonUp(0)) { TouchEvent(); } Vector3 dir = Vector3.zero; if (State == States.WaitingForRoll) { // if the AI should be throwing if (GameType == GameTypes.Single && CurrentPlayer == 2) { // do the ai throw AIThrowDice(); } else { // Get the current acceleration //dir.x = Mathf.Min( Mathf.Abs( Input.acceleration.y ), 10f ) * Mathf.Sign( Input.acceleration.y ); //dir.y = Mathf.Min( Mathf.Abs( Input.acceleration.z ), 5f ) * Mathf.Sign( Input.acceleration.z ); //dir.z = -Mathf.Min( Mathf.Abs( Input.acceleration.x ), 10f ) * Mathf.Sign( Input.acceleration.x ); dir.x = Input.acceleration.y; dir.y = -Input.acceleration.z; dir.z = -Input.acceleration.x; // hack debug dice are thrown if acceleration is high enough. code within die controller ignores this unless dice are throwable if (Mathf.Abs(dir.sqrMagnitude) > 5 && (State == States.WaitingForRoll || State == States.Rolling)) { ThrowDice(dir); } } } // hack force throw of dice with keypress for debug if (Input.GetAxis("Horizontal") > 0 && State == States.WaitingForRoll) { Debug.Log("forced throw"); dir.x = UnityEngine.Random.Range(-10, 10); dir.y = UnityEngine.Random.Range(5, 10); dir.z = UnityEngine.Random.Range(-10, 10); //dir.Normalize(); ThrowDice(dir); } // if we have begun the dice throw process, monitor for dice results if (State == States.Rolling) { // as long as the AI is not currently throwing, player can keep jostling dice if (!(GameType == GameTypes.Single && CurrentPlayer == 2)) { // Get the current acceleration //dir.x = Mathf.Min( Mathf.Abs( Input.acceleration.y ), 10f ) * Mathf.Sign( Input.acceleration.y ); //dir.y = Mathf.Min( Mathf.Abs( Input.acceleration.z ), 5f ) * Mathf.Sign( Input.acceleration.z ); //dir.z = -Mathf.Min( Mathf.Abs( Input.acceleration.x ), 10f ) * Mathf.Sign( Input.acceleration.x ); dir.x = Input.acceleration.y; dir.y = -Input.acceleration.z; dir.z = -Input.acceleration.x; // hack debug dice are thrown if acceleration is high enough. code within die controller ignores this unless dice are throwable if (Mathf.Abs(dir.sqrMagnitude) > 5 && (State == States.WaitingForRoll || State == States.Rolling)) { ThrowDice(dir); } } int DiceTotal = 0; int stoppedDice = 0; for (int i = 0; i < Dice.Count; i++) { // get die controller class GameObject die = Dice[i]; DieController controller = die.GetComponent <DieController>(); // check if die is stopped if (controller.State == DieController.States.Rolled) { DiceTotal += controller.DieValue; stoppedDice++; } } if (stoppedDice == Dice.Count) { Debug.Log("all dice results in"); Debug.Log("total rolled is: " + DiceTotal); SetResult(DiceTotal); ScoreboardResultText = DiceTotal + "! " + ResultString; WaitBeforeDoing(2f, new WaitBeforeDoingDelegate(cameraController.ZoomToField)); cameraController.FinishedMoving += new GameCamera.CameraEventHandler(HandleRollOutcome); State = States.Rolled; } } // hack debug mode if (State == States.WaitingForRoll) { if (Input.GetKeyUp(KeyCode.Keypad1)) { SetResult(4); ScoreboardResultText = "4! " + ResultString; WaitBeforeDoing(2f, new WaitBeforeDoingDelegate(cameraController.ZoomToField)); cameraController.FinishedMoving += new GameCamera.CameraEventHandler(HandleRollOutcome); State = States.Rolled; } else if (Input.GetKeyUp(KeyCode.Keypad2)) { SetResult(8); ScoreboardResultText = "8! " + ResultString; WaitBeforeDoing(2f, new WaitBeforeDoingDelegate(cameraController.ZoomToField)); cameraController.FinishedMoving += new GameCamera.CameraEventHandler(HandleRollOutcome); State = States.Rolled; } else if (Input.GetKeyUp(KeyCode.Keypad3)) { SetResult(10); ScoreboardResultText = "10! " + ResultString; WaitBeforeDoing(2f, new WaitBeforeDoingDelegate(cameraController.ZoomToField)); cameraController.FinishedMoving += new GameCamera.CameraEventHandler(HandleRollOutcome); State = States.Rolled; } else if (Input.GetKeyUp(KeyCode.Keypad4)) { SetResult(12); ScoreboardResultText = "12! " + ResultString; WaitBeforeDoing(2f, new WaitBeforeDoingDelegate(cameraController.ZoomToField)); cameraController.FinishedMoving += new GameCamera.CameraEventHandler(HandleRollOutcome); State = States.Rolled; } else if (Input.GetKeyUp(KeyCode.Keypad5)) { SetResult(5); ScoreboardResultText = "5! " + ResultString; WaitBeforeDoing(2f, new WaitBeforeDoingDelegate(cameraController.ZoomToField)); cameraController.FinishedMoving += new GameCamera.CameraEventHandler(HandleRollOutcome); State = States.Rolled; } } }