using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class NetworkSpawner : NetworkBehaviour
{
public GameObject enemyPrefab;
public GameObject patrol1;
public GameObject patrol2;
void Start()
{
}
public override void OnStartServer()
{
GameObject enemy = (GameObject)Instantiate (enemyPrefab, transform.position, Quaternion.identity);
NetworkServer.Spawn(enemy);
GameObject patrol11 = (GameObject)Instantiate (patrol1, transform.position, Quaternion.identity);
NetworkServer.Spawn (patrol11);
GameObject patrol22 = (GameObject)Instantiate (patrol2, transform.position, Quaternion.identity);
NetworkServer.Spawn (patrol22);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class SimpleEnemy : NetworkBehaviour {
public float speedy;
public Transform[] patrolpoints;
int currentPoint;
public LayerMask dectWhat;
[SerializeField]
Behaviour[] componentsToDisable;
Animator anim;
public GameObject[] Disable;
void Start () {
if (!isLocalPlayer) {
for (int i = 0; i < Disable.Length; i++) {
Disable [i].SetActive(false);
}
for (int i = 0; i < componentsToDisable.Length; i++) {
componentsToDisable [i].enabled = false;
}
}
}
// Update is called once per frame
void FixedUpdate () {
if (!isLocalPlayer)
{
SyncroPatrol ();
}
}
public void SyncroPatrol()
{
Patrol (speedy);
CmdPatrol (speedy);
}
public void Patrol(float speedy)
{
if (transform.position.x == patrolpoints [currentPoint].position.x)
{
currentPoint++;
}
if (currentPoint >= patrolpoints.Length) {
currentPoint = 0;
}
transform.position=Vector2.MoveTowards(transform.position,new Vector2(patrolpoints[currentPoint].position.x,transform.position.y), speedy);
if(transform.position.x>patrolpoints[currentPoint].position.x)
transform.localScale=new Vector3(1,1,1);
else if(transform.position.x= patrolpoints.Length) {
currentPoint = 0;
}
transform.position=Vector2.MoveTowards(transform.position,new Vector2(patrolpoints[currentPoint].position.x,transform.position.y), speedy);
if(transform.position.x>patrolpoints[currentPoint].position.x)
transform.localScale=new Vector3(1,1,1);
else if(transform.position.x
↧