Yea I got pretty offended lol…
Xodus I tried your code and it worked great. However, this not being in an update function will it continue to update the furthest point?
Duugu Your code looks like it would work aswell, I dont want to try it now that I have it working… If its not broken dont fix it right? thanks though!
since we are already on this script, if any of you have any knowledge in PhotonNetworking any help is apprieciated.
Its on the same script as this thread, Im trying to get the enemys to sync on all players screen when they spawn but im coming across an error. I fully understand the error and why it is happening im just not sure how to fix it. I dont like posting my whole script but here it goes
using UnityEngine;
using System.Collections;
public class ZombieSpawn : Photon.MonoBehaviour {
private float minRepeatRate = 1f; //Lowest Random Spawn Rate (Keep at 1 for best results)
private float maxRepeatRate = 1000f; //Highest Random Spawn Rate (Will increase random spawning time if decreased and will decrease random spawning time if inscreased)
public float spawnTime = 15; //Time Before Enemies Spawn
public float repeatRate; //
private float furthestDistance = 0.0f; //Finds Furthest Distance from player
private float distance = 0.0f; //Find all Disrances from player
public Transform[] SpawnPoints; //Holds All Spawn Location information
private Transform furthestSpawnPoint; //Holds Position of the current Furthest Spawn Location
private Transform PlayerTransform; //Holds Players position
public GameObject[] Zombie; //Array of Enemies to spawn, Add as many different enemies you want to spawn in the Inspector area.
void Update ()
{
repeatRate = Random.Range (minRepeatRate, maxRepeatRate); //Randomizes Repeat rates
if (repeatRate <= 1.74) // Increase This To Spawn Enemys Faster
{
Invoke ("SpawnEnemy", spawnTime); // Spawn Enemy
}
}
[PunRPC]
void SpawnEnemy()
{
PlayerTransform = GameObject.FindWithTag("Player").transform; // Gets Current Players Transform
foreach(Transform point in SpawnPoints) // Stores Distances from player to spawnpoints
{
distance = Vector3.Distance(PlayerTransform.position, point.position);
if (distance > furthestDistance)
{
furthestDistance = distance;
furthestSpawnPoint = point;
}
}
int enemyIndex = Random.Range (0, Zombie.Length); // Picks a random Enemy
PhotonNetwork.Instantiate (Zombie[enemyIndex], furthestSpawnPoint.position, furthestSpawnPoint.rotation, 3); // Spawns a Random Enemy at a Random SpawnSpot
}
}
The Error I get is
/Scripts/ZombieSpawn.cs(45,31): error CS1503: Argument `#1' cannot convert `UnityEngine.GameObject' expression to type `string'
The error is appearing because “Zombie[enemyIndex]” is a Game object. And im guessing it needs to be a string.
and With how I have THIS particular script where I cannot just use the prefab name for a string.
because it grabs a random enemy prefab from the enemyIndex line above the instantiate line.
There must be some type of work around here, unfortunatly I have not learned this yet…
Any help is appreciated once again. thanks