void Start() { if (Application.loadedLevelName == "Offline") { GameObject.Find("Scene Camera").SetActive(false); } transform.position = spawnPoint; cam = GetComponentInChildren <Camera>(); cam.enabled = true; AudioListener audio = cam.GetComponent <AudioListener>(); audio.enabled = true; // アニメーション情報の取得 animator = GetComponent <Animator>(); // プレイヤーオブジェクト法線の初期化 playerNormal = new Vector3(0.0f, 1.0f, 0.0f); // プレイヤー位置の地面の法線の初期化 surfaceNormal = transform.localPosition - Vector3.zero; surfaceNormal = surfaceNormal.normalized; // プレイヤー進行方向の初期化 dirVec = Vector3.Scale(transform.forward, new Vector3(1, 1, 1)).normalized; dirVec = Vector3.ProjectOnPlane(dirVec, surfaceNormal); transform.rotation = Quaternion.LookRotation(dirVec, surfaceNormal); // プレイヤー移動量ベクトルの初期化 moveVec = Vector3.zero; // 球面中心点からプレイヤーまでの距離 radPlayer = Mathf.Sqrt( transform.position.x * transform.position.x + transform.position.y * transform.position.y + transform.position.z * transform.position.z); //コントロールマネージャの取得 if (GameObject.Find("PuniconCamera/ControllerManager") != null) { controllerManager = GameObject.Find("PuniconCamera/ControllerManager").GetComponent <Scr_ControllerManager>(); } prePosition = transform.position; //パーティクルスクリプトの取得 //particleManager = GameObject.Find("WalkSmoke").GetComponent<PlayerParticleManager>(); footStampTime = 0; // アニメーション状態の初期化 animationNum = AnimationNum.Idle; audioManager = GameObject.Find("AudioManager").GetComponent <AudioManager> (); }
void Start() { NPCinputVec = new Vector2(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f)); // アニメーション情報の取得 animator = GetComponent <Animator>(); // アニメーション状態の初期化 animationNum = AnimationNum.Idle; }
void Update() { waitTime = waitTime + Time.deltaTime; /// NPCを自動的に動かす( 乱数 ) /// if (modeRand) { if (waitTime > moveTimeRange) { if (move) { move = false; animationNum = AnimationNum.Idle; } else { move = true; NPCinputVec = new Vector2(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f)); NPCinputVec = NPCinputVec.normalized; moveForward = transform.forward * NPCinputVec.y + transform.right * NPCinputVec.x; animationNum = AnimationNum.Walk; } waitTime = 0.0f; } } /// NPCを自動的に動かす( 目的地を往復 ) /// else { if (waitTime > moveTimeRange && !move) { move = true; waitTime = 0.0f; } } }
public void actionPlay() { animator.SetBool("is_action", true); animationNum = AnimationNum.Action; }
void FixedUpdate() { // プレイヤー位置の地面の法線の更新 surfaceNormal = transform.position - Vector3.zero; surfaceNormal = surfaceNormal.normalized; /// 移動処理 // カメラ進行方向ベクトルを取得 //Vector3 cameraForward = Vector3.Scale(camera.transform.forward, new Vector3(1, 1, 1)).normalized; Vector3 cameraForward = Vector3.Scale(cameraStand.GetCameraDirection, new Vector3(1, 1, 1)).normalized; Vector3 moveForward; // 方向キーの入力値とカメラの向きから、移動方向を決定 //moveForward = cameraForward * inputVertical + Camera.main.transform.right * inputHorizontal; moveForward = cameraForward * inputVecN.y + cam.transform.right * inputVecN.x; // 入力量によって移動速度を変える if (VecLength < moveDead) { move = false; animationNum = AnimationNum.Idle; } else { move = true; } if (move) { if (VecLength < (puniVecMax * moveThre)) { moveVec = Vector3.ProjectOnPlane(moveForward, surfaceNormal) * moveWalkSpeed; animationNum = AnimationNum.Walk; } else if (VecLength >= (puniVecMax * moveThre)) { moveVec = Vector3.ProjectOnPlane(moveForward, surfaceNormal) * moveRunSpeed; animationNum = AnimationNum.Running; } } else { moveVec = Vector3.ProjectOnPlane(moveForward, surfaceNormal) * moveWalkSpeed; animationNum = AnimationNum.Idle; } // 慣性 moveVec += (Vector3.zero - moveVec) * moveIn; // 移動速度を位置に足しこむ if (move) { transform.position += moveVec; } if (moveVec.magnitude > 0) { dirVec = moveVec.normalized; } // プレイヤーの回転 if (move || (deadTrans && (VecLength > moveDeadMin))) { transform.rotation = Quaternion.LookRotation(dirVec, surfaceNormal); } // アニメーション状態取得 if (moveVec.magnitude > 0) { move = true; } else { move = false; } /// アニメーション状態によって動作を変える /// switch (animationNum) { case AnimationNum.Idle: { animator.SetBool("is_action", false); animator.SetBool("is_walk", false); animator.SetBool("is_running", false); particleManager.SetSmokeFlg(false); seCnt = 0; break; } case AnimationNum.Walk: { animator.SetBool("is_walk", true); animator.SetBool("is_running", false); particleManager.SetSmokeFlg(false); footStampTime += Time.deltaTime; if (footStampTime > footStampSetTime) { footStampTime = 0; Instantiate(footStampPrefab, transform.position, transform.rotation); } if (seCnt == 20) { audioManager.Play_SE(AudioManager.SE.Run); seCnt = 0; } else { seCnt++; } break; } case AnimationNum.Running: { animator.SetBool("is_running", true); //animator.SetBool("is_walk", false); particleManager.SetSmokeFlg(true); footStampTime += Time.deltaTime; if (footStampTime > footStampSetTime) { footStampTime = 0; Instantiate(footStampPrefab, transform.position, transform.rotation); } if (seCnt == 15) { audioManager.Play_SE(AudioManager.SE.Run); seCnt = 0; } else { seCnt++; } break; } } // 球面中心点からプレイヤーまでの距離更新] radPlayer = Mathf.Sqrt( transform.position.x * transform.position.x + transform.position.y * transform.position.y + transform.position.z * transform.position.z); // プレイヤー位置差分の取得 difPosition = transform.position - prePosition; prePosition = transform.position; }