Instantiating an enemy killable by all players

Options
Hi everyone ! I'm slightly new to Photon Network and even by reading for a while the documentation, i couldn't find any solution to the problem i ran into ( i'm french so my understanding of written english is rarely good enough.. :neutral: ). I'm making a 2D coop platformer, and i'm trying to make an enemy spawn for all players when one of them runs close to a specific GameObject. The problem is, when using PhotonNetwork.Instantiate(...), my enemies spawns by 2/3/4 depending on the number of players, when i'm just expecting one, and each player can kill only one enemy among them all, the others will be unkillable for him. Ofc when using photonView.isMine, only one enemy does spawn, but i'm the only one who can kill it. I'm kinda runnin out ouf ideas, here is the code i'm using. And i would like to precise that my enemy has a photonView attached to it, along with a Photon Transform View and a Photon Animator View.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class SlimeSpawn : MonoBehaviour
{
    private bool spawned=false;
    public GameObject slimePrefab;
    public PhotonView photonView;
 
    void OnTriggerEnter2D(Collider2D coll){
 
 
      if(coll.gameObject.CompareTag("Player")&&spawned ==false){
          spawned = true;
          StartCoroutine(Spawning());
      }
 
    }
 
    public IEnumerator Spawning(){
      yield return new WaitForSeconds(0.5f);
      PhotonNetwork.Instantiate("slimePrefab", this.transform.position, Quaternion.identity,0);
      PhotonNetwork.Destroy(this.gameObject);
    }
}

If any of you has any idea, i'd be really grateful ! Thanks for reading !

Comments

  • Are you planning to instantiate ONE enemy for each player and only that specific player can kill the enemy? or the plan is to create ONLY ONE enemy at the time and everyone can kill it ?
    For the later, it seems only the master client have to instantiate the enemy at given time.
  • Plancton
    Options
    The idea was to instantiate only one enemy at the time and everyone can kill it. But when i use PhotonNetwork.isMasterClient, only the Master Client can kill it, it won't be killable by the others players.