void OnTriggerEnter(Collider collider) { if (_isUseItem) { return; } //当たったプレイヤーがアイテムを持っていたら移動する if (collider.CompareTag("Player")) { _agent.enabled = false; _navController.enabled = false; _obstacle.enabled = true; var player = collider.GetComponent <Player2Controller>(); // プレイヤーにアイテムを持っているかどうかのフラグと取得する関数を用意しておく if (player.IsObstacleItem1()) { _agent.enabled = true; _navController.enabled = true; _obstacle.enabled = false; _isUseItem = true; //_agent.SetDestination(_useItemPos); _navController.SetDestination(_useItemPos); flower1UI.SetActive(false); GetComponent <AudioSource>().Play(); } } }
void Update() { if (Input.GetButtonDown("Fire1")) { Debug.Log("mouse down"); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, _rayRange)) { Debug.Log("hit"); _targetPos = hit.point; //_agent.SetDestination(_targetPos); _navController.SetDestination(_targetPos); //移動を開始する時、アニメーションをwalkにする player_walk = true; if (player_walk == true) { player_Animator.SetBool("move", true); } } } //目的に到着したらアニメーションをidleにする if (_navController.IsReached) { player_Animator.SetBool("move", false); } //クリックしたら非表示にする if (Input.GetMouseButtonDown(0)) { letterUI.SetActive(false); hint2UI.SetActive(false); } }
void Start() { _obstacle = GetComponent <NavMeshObstacle>(); _agent = GetComponent <NavMeshAgent>(); _navController = GetComponent <AM1.Nav.NavController>(); // 初期状態はstartPosに移動するようにする _targetPos = _startPos; // _agent.SetDestination(_targetPos); _navController.SetDestination(_targetPos); }