void OnRobotBombShoot() { gameManager.FireBomb(robot.GetBoneSocket("Bone WeaponSocket").position, _aimPosition); }
// Update //-------------------------------------------------- void Update() { if (!gameManager.IsLive()) { aimUI.enabled = false; return; } if (!_isLive) { aimUI.enabled = false; return; } // Set Aim by Mouse Position Vector3 mousePos_Screen = Input.mousePosition; mousePos_Screen.z = gameManager.camera_Game.farClipPlane; Ray mouseRay = gameManager.camera_Game.ScreenPointToRay(mousePos_Screen); if (mouseRay.direction.z != 0.0f) { float tVector = -1.0f * mouseRay.origin.z / mouseRay.direction.z; Vector3 mousePos_World = mouseRay.GetPoint(tVector); _aimPosition = mousePos_World; Vector2 aimScreenPoint = gameManager.camera_Game.WorldToScreenPoint(_aimPosition); Vector3 aimUIPoint = gameManager.camera_UI.ScreenToWorldPoint(aimScreenPoint); aimUIPoint.z = aimUI.transform.position.z; aimUI.transform.position = aimUIPoint; } aimUI.enabled = true; bool isLeftIsForward = (_aimPosition.x < transform.position.x); // Set Scale X of Girl if (!isLeftIsForward) { if (transform.localScale.x > 0.0f) { transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f); } } else { if (transform.localScale.x < 0.0f) { transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); } } // Move Girl Vector3 girlPosition = transform.position; if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { if (isLeftIsForward) { girlAnimator.SetInteger("Move", MOVE_FORWARD); girlPosition.x -= forwardVelocity * Time.deltaTime; } else { girlAnimator.SetInteger("Move", MOVE_BACKWARD); girlPosition.x -= backwardVelocity * Time.deltaTime; } } else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { if (isLeftIsForward) { girlAnimator.SetInteger("Move", MOVE_BACKWARD); girlPosition.x += backwardVelocity * Time.deltaTime; } else { girlAnimator.SetInteger("Move", MOVE_FORWARD); girlPosition.x += forwardVelocity * Time.deltaTime; } } else { girlAnimator.SetInteger("Move", MOVE_STAND); } //Modify Position of Girl if (girlPosition.x < gameManager.leftBound.position.x) { girlPosition.x = gameManager.leftBound.position.x; } if (girlPosition.x > gameManager.rightBound.position.x) { girlPosition.x = gameManager.rightBound.position.x; } RaycastHit raycastHit_GirlPosition; bool isHit = Physics.Raycast(girlPosition + new Vector3(0.0f, 20.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), out raycastHit_GirlPosition, 100); if (isHit && raycastHit_GirlPosition.collider != null) { float nextGirlPosY = raycastHit_GirlPosition.point.y - (girlFootPosY_Default.localPosition.y); if (Mathf.Abs(girlPosition.y - nextGirlPosY) < 0.2f) { girlPosition.y = girlPosition.y * 0.7f + nextGirlPosY * 0.3f; } else { girlPosition.y = nextGirlPosY; } } transform.position = girlPosition; if (_isIKCalculate) { //Set Aim Helper Bone Position girl.SetBonePosition("Helper Aim", _aimPosition, Space.World); //Set Foot Height Vector3 footPos_L = girl.GetBoneSocket("Helper Foot L").transform.position; Vector3 footPos_R = girl.GetBoneSocket("Helper Foot R").transform.position; RaycastHit raycastHit_FootL; RaycastHit raycastHit_FootR; bool isHit_FootL = Physics.Raycast(footPos_L + new Vector3(0.0f, 10.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), out raycastHit_FootL, 30); bool isHit_FootR = Physics.Raycast(footPos_R + new Vector3(0.0f, 10.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), out raycastHit_FootR, 30); if (isHit_FootL && raycastHit_FootL.collider != null && raycastHit_FootL.point.y < transform.position.y) { girl.SetBonePositionConstraintBySurface("Helper Foot L", girlFootPosY_Default.position.y, raycastHit_FootL.point.y, girlFootPosY_Min.position.y, girlFootPosY_Max.position.y, ConstraintSurface.Ysurface, Space.World); } if (isHit_FootR && raycastHit_FootR.collider != null && raycastHit_FootR.point.y < transform.position.y) { girl.SetBonePositionConstraintBySurface("Helper Foot R", girlFootPosY_Default.position.y, raycastHit_FootR.point.y, girlFootPosY_Min.position.y, girlFootPosY_Max.position.y, ConstraintSurface.Ysurface, Space.World); } } //Robot Movement Vector3 robotTargetPos = Vector3.zero; if (isLeftIsForward) { robotTargetPos = transform.position + new Vector3(robotDistX, 0.0f, 0.0f); } else { robotTargetPos = transform.position + new Vector3(-robotDistX, 0.0f, 0.0f); } if (_aimPosition.x > robotTransform.position.x) { if (robotTransform.localScale.x > 0.0f) { robotTransform.localScale = new Vector3(-1.0f, 1.0f, 1.0f); } } else { if (robotTransform.localScale.x < 0.0f) { robotTransform.localScale = new Vector3(1.0f, 1.0f, 1.0f); } } Vector3 robotPosition = robotTransform.position; float deltaX = robotTargetPos.x - robotTransform.position.x; if (Mathf.Abs(robotPosition.x - transform.position.x) > robotDistX) { if (deltaX < 0) { robotPosition.x -= Time.deltaTime * robotVelocity; } else { robotPosition.x += Time.deltaTime * robotVelocity; } //When moving if (robotTransform.localScale.x > 0) { //Look Left if (deltaX < 0) { robotAnimator.SetInteger("Move", MOVE_ROBOT_LEFT); } else { robotAnimator.SetInteger("Move", MOVE_ROBOT_RIGHT); } } else { //Look Right if (deltaX < 0) { robotAnimator.SetInteger("Move", MOVE_ROBOT_RIGHT); } else { robotAnimator.SetInteger("Move", MOVE_ROBOT_LEFT); } } } else { robotAnimator.SetInteger("Move", MOVE_STAND); } //Modify Position of Robot if (robotPosition.x < gameManager.leftBound.position.x) { robotPosition.x = gameManager.leftBound.position.x; } if (robotPosition.x > gameManager.rightBound.position.x) { robotPosition.x = gameManager.rightBound.position.x; } RaycastHit raycastHit_RobotPosition; bool isHit_RobotPosition = Physics.Raycast(robotPosition + new Vector3(0.0f, 20.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), out raycastHit_RobotPosition, 100); if (isHit_RobotPosition && raycastHit_RobotPosition.collider != null) { float nextRobotPosY = raycastHit_RobotPosition.point.y - (robotFootPosY_Default.localPosition.y); if (Mathf.Abs(robotPosition.y - nextRobotPosY) < 0.2f) { robotPosition.y = robotPosition.y * 0.7f + nextRobotPosY * 0.3f; } else { robotPosition.y = nextRobotPosY; } } robotTransform.position = robotPosition; if (_isIKCalculate) { //Set Aim Helper Bone Position robot.SetBonePosition("Helper Aim", _aimPosition, Space.World); RaycastHit raycastHit_RobotFootL; RaycastHit raycastHit_RobotFootR; bool isHit_RobotFootL = Physics.Raycast(robotFootRaycast_L.position, new Vector3(0.0f, -1.0f, 0.0f), out raycastHit_RobotFootL, 30); bool isHit_RobotFootR = Physics.Raycast(robotFootRaycast_R.position, new Vector3(0.0f, -1.0f, 0.0f), out raycastHit_RobotFootR, 30); if (isHit_RobotFootL && raycastHit_RobotFootL.collider != null) { robot.SetBonePositionConstraintBySurface("Helper Foot Front L", robotFootPosY_Default.position.y, raycastHit_RobotFootL.point.y, robotFootPosY_Min.position.y, robotFootPosY_Max.position.y, ConstraintSurface.Ysurface, Space.World); robot.SetBonePositionConstraintBySurface("Helper Foot Back L", robotFootPosY_Default.position.y, raycastHit_RobotFootL.point.y, robotFootPosY_Min.position.y, robotFootPosY_Max.position.y, ConstraintSurface.Ysurface, Space.World); } if (isHit_RobotFootR && raycastHit_RobotFootR.collider != null) { robot.SetBonePositionConstraintBySurface("Helper Foot Front R", robotFootPosY_Default.position.y, raycastHit_RobotFootR.point.y, robotFootPosY_Min.position.y, robotFootPosY_Max.position.y, ConstraintSurface.Ysurface, Space.World); robot.SetBonePositionConstraintBySurface("Helper Foot Back R", robotFootPosY_Default.position.y, raycastHit_RobotFootR.point.y, robotFootPosY_Min.position.y, robotFootPosY_Max.position.y, ConstraintSurface.Ysurface, Space.World); } } // Shoot if (Input.GetMouseButton(0)) { if (_isGirlShootable) { girlAnimator.SetTrigger("Shoot"); _isGirlShootable = false; } } // Fire Bombs if (Input.GetMouseButton(1)) { if (_isRobotShootable) { robotAnimator.SetTrigger("Shoot"); _isRobotShootable = false; } } }