タグ「Freeze001」がついているオブジェクトに対して、マウスの左ボタンを押したときに、プレイヤーの位置を固定しようとしたのですが、上手くいきません。
インスペクター上では、constraintsのFreeze Position とFreeze Rotationにチェックがついているのですが、プレイヤーが動いてしまいます。
FreezeTargetにFPSControllerをアタッチはしています。
どうすれば解決出来るでしょうか? 回答をよろしくお願いします。
C#
1public class Freeze : MonoBehaviour {23 public Transform FreezeTarget;45// Use this for initialization6voidStart(){7}89// Update is called once per frame10voidUpdate(){1112if(Input.GetMouseButtonDown(0)){13 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);14 RaycastHit hitInfo;15if(Physics.Raycast(ray, out hitInfo)){16if(hitInfo.collider.gameObject.tag =="Freeze001"){17 FreezeTarget.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;18 Debug.Log("hit");19}20}21}2223}24}
1// 中略23 public bool isFrozen = false;// こんな変数を追加し...45// Update is called once per frame6 private voidUpdate()7{8if(isFrozen)// trueならUpdate内の処理を丸ごとスキップする9{10return;11}1213RotateView();14// the jump state needs to read here to make sure it is not missed15if(!m_Jump)16{17 m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");18}1920if(!m_PreviouslyGrounded && m_CharacterController.isGrounded)21{22StartCoroutine(m_JumpBob.DoBobCycle());23PlayLandingSound();24 m_MoveDir.y =0f;25 m_Jumping = false;26}27if(!m_CharacterController.isGrounded &&!m_Jumping && m_PreviouslyGrounded)28{29 m_MoveDir.y =0f;30}3132 m_PreviouslyGrounded = m_CharacterController.isGrounded;33}3435// 中略3637 private voidFixedUpdate()38{39if(isFrozen)// trueならFixedUpdate内の処理を丸ごとスキップする40{41return;42}4344float speed;45GetInput(out speed);46// always move along the camera forward as it is the direction that it being aimed at47 Vector3 desiredMove = transform.forward * m_Input.y + transform.right * m_Input.x;4849// get a normal for the surface that is being touched to move along it50 RaycastHit hitInfo;51 Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,52 m_CharacterController.height /2f, Physics.AllLayers, QueryTriggerInteraction.Ignore);53 desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;5455 m_MoveDir.x = desiredMove.x * speed;56 m_MoveDir.z = desiredMove.z * speed;575859if(m_CharacterController.isGrounded)60{61 m_MoveDir.y =-m_StickToGroundForce;6263if(m_Jump)64{65 m_MoveDir.y = m_JumpSpeed;66PlayJumpSound();67 m_Jump = false;68 m_Jumping = true;69}70}71else72{73 m_MoveDir += Physics.gravity * m_GravityMultiplier * Time.fixedDeltaTime;74}75 m_CollisionFlags = m_CharacterController.Move(m_MoveDir * Time.fixedDeltaTime);7677ProgressStepCycle(speed);78UpdateCameraPosition(speed);7980 m_MouseLook.UpdateCursorLock();81}8283// 中略
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/11/30 10:05