unity3dでの鬼ごっこゲームを作成しております。
プレイヤーと鬼を2対ずつ用意をしているのですが、鬼が1対のプレイヤーを捕まえた際にプレイヤーが二体とも捕まってしまうようになってしまいます。
プレイヤーごとにboolの判定を分けたい場合どのようにすれば良いかアドバイスをいただけますと幸いです。
下記にスクリプトを追加させていただきました。
PlayerController,OniControllerでの実装をしております。
鬼がプレイヤーに近付いたらそのプレイヤーが捕獲されるにしたいと考えております。(実際は他のプレイヤーも所定の場所に飛ばされてしまいます。)
PlayerScripts
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class PlayerController : MonoBehaviour 7{ 8 [SerializeField] public OniController anotherScript1; 9 10 void Start() 11 { 12 13 14 anotherScript = GetComponent<UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter>(); 15 16 GameObject anotherObject = GameObject.FindWithTag("Oni"); 17 anotherScript1 = anotherObject.GetComponent<OniController>(); 18 19 20 } 21 22 void Update() 23 { 24 if (anotherScript1.isRouya == true) 25 { 26 float rouya_y = 1.5f; 27 28 transform.position = new Vector3(65, rouya_y, 65); 29 30 } 31 } 32 33 34 35 36} 37
OniController
C#
1 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using UnityEngine.UI; 6 7public class OniController : MonoBehaviour 8{ 9 //プレイヤーの取得 10 List<GameObject> Players = new List<GameObject>(); 11 12 public bool isRouya; 13 14 15 16 [SerializeField] private Oni.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter anotherScript; 17 18 19 20 void Start() 21 { 22 //プレイヤーの取得 23 Players.AddRange(GameObject.FindGameObjectsWithTag("Player")); 24 25 anotherScript = GetComponent<Oni.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter>(); 26 27 28 29 30 } 31 32 33 public void OnCollisionStay(Collision hit) 34 { 35 // 接触対象はPlayerタグですか? 36 if (hit.gameObject.tag == "Player") 37 { 38 //Debug.Log("プレイヤーと接触している"); 39 40 OnButtonHokaku(); 41 42 } 43 44 } 45 46 public void OnButtonHokaku() 47 { 48 49 50 51 52 Invoke("Rouya", 0.7f); 53 anotherScript.TouchStart(); 54 Invoke("OnTouchEnd", 0.5f); 55 56 57 58 59 60 61 62 } 63 public void Rouya() 64 { 65 66 67 isRouya = true; 68 69 70 71 } 72 //アニメーションです。 73 public void OnTouchEnd() 74 { 75 anotherScript.TouchEnd(); 76 } 77 78 79 80 81} 82 83 84
回答1件
あなたの回答
tips
プレビュー