private Vector3 goalPos; //The current goal position void Awake() { //SEARCHING INSTANTIATION CODE search = GetComponent <SearchingState>(); //we make search hold a reference of the SearchState script inASearch = false; //Set the searching state false by default //GEMS INSTANTIATION CODE gemTracker = gemTrackerObject.GetComponent <GemTracker>(); //This is to allows us to keep track of gems gemPositions = new List <Vector3>(); //create new list of Vector3 positions for the gems searchNewGem = true; //set the searchNewGem to true upon start closestGem = new Vector3(); //SIGHT INSTANTIATION CODE sight = GetComponent <SightController>(); //ATTACKING INSTANTIATION CODE attack = GetComponent <AttackingState>(); player = GameObject.FindGameObjectWithTag("Player"); //HEALTH INSTANTIATION CODE health = GetComponent <NPC1Health>(); //CHASE INSTANTIATION CODE chasing = false; //PLAYER DETECTION INSTANTIATION CODE playerDetectionTimer = 3f; playerPos = new Vector3(); //FLEEING INSTATIATION CODE escapePos = new Vector3(); goalPos = new Vector3(); fleeing = false; }
public void RemoveTarget(SightController controller) { if (targetList.Contains(controller)) { targetList.Remove(controller); } }
public void AddTarget(SightController controller) { if (!targetList.Contains(controller)) { targetList.Add(controller); } }
void Update() { if (isLocalPlayer) { // 计算奔跑时间 float lastShowRunEnergy = showRunEnergy; float now = Time.realtimeSinceStartup; if (inputRun) { showRunEnergy = Mathf.Max(Mathf.Min(leftRunEnergy - (now - runStartTime) * CONSUME_SPEED, runEnergy), 0); } else { showRunEnergy = Mathf.Max(Mathf.Min(leftRunEnergy + (now - runEndTime) * RECOVER_SPEED, runEnergy), 0); } if (!lastShowRunEnergy.Equals(showRunEnergy)) { EventMgr.instance.TriggerEvent <float, float>("RefreshRunEnergy", showRunEnergy, runEnergy); } if (hudControl != null) { hudControl.ShowSliderEnergy(showRunEnergy, runEnergy); } // 计算视野 bool warn = false; SightMgr.instance.Check(sightController, sightRange, sightAngle, bodyRadius * 6, ref targetsInSight, ref targetsOutSight); for (int i = 0; i < targetsInSight.Count; i++) { targetsInSight[i].BecameVisible(); } for (int i = 0; i < targetsOutSight.Count; i++) { SightController target = targetsOutSight[i]; target.BecameInvisible(); if (!warn) { TestController player = target.GetComponent <TestController>(); if (player != null && player.inputRun && Vector3.Distance(sightController.transform.position, player.thisTransform.position) < WARN_DISTANCE) { warn = true; } } } if (hudControl != null) { if (warn && !hudControl.IsWarnShow()) { // 显示警戒标识和提示 hudControl.ShowWarnIcon(); hudControl.ShoweHudTip("听到脚步声!"); } else if (!warn && hudControl.IsWarnShow()) { // 隐藏警戒标识 hudControl.HideWarnIcon(); } } } }
void Awake() { sight = GetComponent <SightController>(); search = GetComponent <SearchingState>(); currPlayerPos = new Vector3(1000f, 1000f, 1000f); lastPlayerSeenPos = new Vector3(0f, 0f, 0f); chaseTimer = 5f; }
void Start() { if (hudControl == null) { hudControl = new HudControl(); hudControl.Init(thisTransform); hudControl.CreateHudName(playerName); hudControl.CreateHudScore(this.score); } if (isLocalPlayer) { sight.enabled = true; sight.range = sightRange; sight.spotAngle = sightAngle; quan.SetActive(true); ripArea.SetActive(false); EventMgr.instance.TriggerEvent("beginProcessInput"); EventMgr.instance.AddListener <Vector3>("joystickMove", OnMove); EventMgr.instance.AddListener("joystickStop", OnStop); EventMgr.instance.AddListener <bool>("catchPress", OnCatchPress); EventMgr.instance.AddListener <bool>("runPress", OnRunPress); EventMgr.instance.AddListener <GameObject>("OnSignPress", OnSignPress); EventMgr.instance.AddListener("boxPress", OnBoxPress); } else { sight.enabled = false; quan.SetActive(false); ripArea.SetActive(false); } leftRunEnergy = runEnergy; if (hasAuthority) { RipMgr.instance.AddTarget(gameObject, bodyRadius); } if (isClient) { sightController = gameObject.AddMissingComponent <SightController>(); } // 有可能是中途进入游戏 model.SetActive(!hideInfo.hide); if (!hideInfo.hide && sightController.InSight) { if (hudControl != null) { hudControl.Show(); } else if (hudControl != null) { hudControl.Hide(); } } }
void Start() { audioSource = GetComponent <AudioSource> (); controller = GetComponent <Controller2D> (); sightController = GetComponent <SightController> (); animator = GetComponent <Animator> (); gravity = -(2 * jumpHeight) / Mathf.Pow(timeToJump, 2); jumpVelocity = Mathf.Abs(gravity) * timeToJump; backLimit = transform.position.x - 10f; //GameObject.FindGameObjectWithTag ("ScoreManager").GetComponent<ScoreManager> ().score = score; }
void Start() { audioSource = GetComponent<AudioSource> (); controller = GetComponent<Controller2D> (); sightController = GetComponent<SightController> (); animator = GetComponent<Animator> (); gravity = -(2 * jumpHeight) / Mathf.Pow (timeToJump, 2); jumpVelocity = Mathf.Abs(gravity) * timeToJump; backLimit = transform.position.x - 10f; //GameObject.FindGameObjectWithTag ("ScoreManager").GetComponent<ScoreManager> ().score = score; }
public void Check(SightController center, float sightRange, float angle, float selfRadius, ref List <SightController> targetsInSight, ref List <SightController> targetsOutSight) { targetsInSight.Clear(); targetsOutSight.Clear(); for (int i = 0; i < targetList.Count; i++) { if (Check(center, sightRange, angle, selfRadius, targetList[i].gameObject)) { targetsInSight.Add(targetList[i]); } else { targetsOutSight.Add(targetList[i]); } } }
public bool Check(SightController center, float sightRange, float angle, float selfRadius, GameObject checkTarget) { bool inSight = false; // 坐标和朝向去除y坐标影响 Vector3 pos = center.GetSource().position; pos.y = 0; Vector3 forward = center.GetSource().forward; forward.y = 0; // 自身看得见 if (checkTarget == center.gameObject) { return(true); } Vector3 targetPos = checkTarget.transform.position; targetPos.y = 0; Vector3 delta = targetPos - pos; // 与自身圆是否相交 if (Vector3.Distance(targetPos, pos) <= selfRadius) { return(true); } // 与扇形圆是否相交 float distance = delta.magnitude; if (distance >= sightRange) { return(inSight); } // 判断方向与点的夹角是否大于angle的一半 if (Vector3.Angle(forward, delta) > angle / 2) { return(inSight); } // 判断视野中有没有遮挡 if (Physics.Raycast(center.GetSource().position, delta, distance, layerMask)) { return(inSight); } inSight = true; return(inSight); }
void Start() { playerHealthController = FindObjectOfType<PlayerHealthController> (); pathContainer = path.GetComponent<PathContainer> (); pathNode = pathContainer.GetClosestPath (transform.position); _sc = FindObjectOfType<SightController> (); SendMessage ("Audio_SearchingEnter"); transform.position = pathHead.transform.position; }
// Use this for initialization void Start() { _sc = GetComponent<SightController> (); _listener = FindObjectOfType<AkAudioListener>(); }
// Use this for initialization void Start() { _sc = FindObjectsOfType<SightController> ()[0]; }