//chase players
` ` `
Using System. The Collections;
Using System. Collections. Generic;
Using UnityEngine;
Public class move_shootPOS: MonoBehaviour {
Private int speed;
Private int distance_follow=20;//a maximum distance of target track players
Private GameObject player;
Private Vector3 initPos;
Public float bleed=100;
Public float Bleed {set; The get; }
Public Vector3 InitPosition
{
The get {return initPos; }
The set {initPos=value; }
}
Void the Start ()
{
Player=GameObject. Find (" player ");
//refer to the player's normal movement speed, set the speed of the target tracking the player
Speed=player. GetComponent
}
Void OnCollisionEnter (Collision other)
{
If (other) starts) gameObject==player)
{
Bleed -;
If (bleed & lt;=0)
{
//HP reduced to 0 to players, the game failed
UnityEngine. SceneManagement. SceneManager. LoadScene (" end ");
}
}
}
//Update is called once per frame
Void the Update ()
{
//target real-time look at players
The transform. LookAt (player. The transform);
//to determine whether a player target distance is less than the maximum tracking distance, if so, it began to track
If (Vector3. Short (the transform. The position, the player. The transform. The position) & lt; Distance_follow)
{
//set the speed of the target tracking the player to player movement speed of 75%
Transform. The position=Vector3. MoveTowards (transform. The position, the player. The transform. The position and speed * Time deltaTime * 0.75 f);
}
}
}
` ` `
//new monster
` ` `
Using System. The Collections;
Using System. Collections. Generic;
Using UnityEngine;
Public class target_New: MonoBehaviour {
//Use this for initialization
[SerializeField]
Private GameObject m_target;
Private Vector3 initPos;
Void the Start ()
{
InitPos=the transform. The position;
While (transform) childCount & lt; 5)
{
CreateNewTarget ();
}
}
Void CreateNewTarget ()
{
Float x=Random. Range (10, 10);
Float z=Random. Range (10, 10);
Vector3 pos=new Vector3 (x + initPos. X, the transform. The position, y, z + initPos. Z);
GameObject m_st=Instantiate (m_target);
M_st. The transform. The position=pos;
M_st. GetComponent
M_st. Tag="target";
M_st. The transform. The parent=transform;//specify the new generation game object's parent object
M_st. SetActive (false);//hide newly generated game object
}
//Update is called once per frame
Void the Update ()
{
If (the transform childCount & lt; 5)
{
CreateNewTarget ();
}
}
}
` ` `
//show the monster
` ` `
Using System. The Collections;
Using System. Collections. Generic;
Using UnityEngine;
Public class target_IsShow: MonoBehaviour {
//Use this for initialization
Private GameObject m_player;
Void the Start ()
{
M_player=GameObject. Find (" player ");//to find players game object
}
//Update is called once per frame
Void the Update ()
{
//to detect whether the player into the target within the specified range, if the scope, displays all the target;
//if players leave, the hidden target
If (Vector3. Short (the transform. The position, m_player. The transform. The position) & lt; 20)
{
For (int I=0; I & lt; The transform. ChildCount; I++)
{
The transform. The GetChild (I). GameObject. SetActive (true);
}
}
The else
{
For (int I=0; I & lt; The transform. ChildCount; I++)
{
//the transform. GetChild (I). The gameObject. SetActive (false);
GameObject child=transform. GetChild (I). The GameObject.
Child. SetActive (false);
//hide target, make the target back to the initial position
Child. The transform. The position=child. GetComponent
}
//the current activities of the target, away from the involves after 80, automatic hidden
For (int I=0; I & lt; The transform. ChildCount; I++)
{
GameObject child=transform. GetChild (I). The GameObject.
If (child. ActiveSelf & amp; & Vector3. Short (the transform. The position, child. The transform. The position) & gt; 80)
{
Child. SetActive (false);
//hide target, make the target back to the initial position
Child. The transform. The position=child. GetComponent
}
}
}
` ` `
Because running video can not coming, can solve the great god of genuflect is begged for help
CodePudding user response:
This problem is not delete the referenceCodePudding user response:
Object has been destroyed, are you still in use