// Update is called once per frame void Update() { Vector3 mainCharacterForward = m_MainCharacter.transform.forward; Vector3 toMainCharacter = m_MainCharacter.transform.position - this.gameObject.transform.position; FollowTheMainCharacter02 script = this.gameObject.GetComponent <FollowTheMainCharacter02>(); float angle = Vector3.Angle(mainCharacterForward, toMainCharacter); if (angle < 90) { if (null == script) { script = this.gameObject.AddComponent <FollowTheMainCharacter02>(); script.m_MainCharacter = this.m_MainCharacter; } script.enabled = true; } else { if (null != script) { script.enabled = false; } } }
// Update is called once per frame void Update() { Vector3 mainCharacterForward = m_MainCharacter.transform.forward; Vector3 toMainCharacter = m_MainCharacter.transform.position - this.gameObject.transform.position; // Debug.Log( toMainCharacter.magnitude ) ; float angle = Vector3.Angle(mainCharacterForward, toMainCharacter); if (angle < 90) { if ("FollowTheMainCharacter02" != m_LastScriptName) { DisablePreviousScript(); FollowTheMainCharacter02 script = this.gameObject.GetComponent <FollowTheMainCharacter02>(); if (null == script) { script = this.gameObject.AddComponent <FollowTheMainCharacter02>(); script.m_MainCharacter = this.m_MainCharacter; } script.enabled = true; m_LastScriptName = "FollowTheMainCharacter02"; } } else if (toMainCharacter.magnitude < 5) { if ("AwayFromTheMainCharacter01" != m_LastScriptName) { DisablePreviousScript(); AwayFromTheMainCharacter01 script = this.gameObject.GetComponent <AwayFromTheMainCharacter01>(); if (null == script) { script = this.gameObject.AddComponent <AwayFromTheMainCharacter01>(); script.m_MainCharacter = this.m_MainCharacter; } script.enabled = true; m_LastScriptName = "AwayFromTheMainCharacter01"; } } else { if ("RotateAroundLocalX" != m_LastScriptName) { DisablePreviousScript(); RotateAroundLocalX script = this.gameObject.GetComponent <RotateAroundLocalX>(); if (null == script) { script = this.gameObject.AddComponent <RotateAroundLocalX>(); script.m_Right = new Vector3(0, 1, 0); } script.enabled = true; m_LastScriptName = "RotateAroundLocalX"; } } }