Search Unity

Third Party Instanciate Object to my player doesn't work..[Photon Networking]

Discussion in 'Multiplayer' started by shuskry, Apr 10, 2017.

  1. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    Hi everybody!
    i have some trouble with instanciate prefab to my player with Photon Networking..
    I try to instanciate a object locally to my player, but when i use
    "Instantiate(UpAnimation, ect...);"
    This is appear on the wrong player..

    i try to do this with view.IsMine but nothing change ...
    there is my code, All work on the multiplayer but not the instanciation..

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;


    public class PlayerStats : MonoBehaviour
    {

    PhotonView _view;
    public int playerHealth;
    public int currentPlayerHealth;
    public GameObject checkpoint;
    public Vector2 checkpointPosition;
    public int currentLevel;
    public int currentExp;
    public int[] toLevelUp;
    Text levelText;
    public int maxXp;
    Text XPText;
    public GameObject UpAnimation;



    void Start()
    {

    _view = GetComponent();

    currentPlayerHealth = playerHealth;
    checkpointPosition = checkpoint.transform.position;
    addExperience(0);
    levelText = GameObject.Find("LvlText").GetComponent();
    XPText = GameObject.Find("XpText").GetComponent();

    }

    void Update()
    {
    levelText.text = "Lvl: " + currentLevel;
    XPText.text = "XP : " + currentExp + "/" + maxXp;

    }

    public void addExperience(int experienceToAdd)
    {

    currentExp += experienceToAdd;

    if (currentExp >= toLevelUp[currentLevel])
    {

    currentLevel++;
    maxXp = toLevelUp[currentLevel];
    Debug.Log(" UP !!");
    Instantiate(UpAnimation, transform.FindChild("PlayerInstanciate").transform.position, transform.rotation);

    }

    }


    public void TakeDamage(int damage)
    {

    currentPlayerHealth -= damage;


    if (currentPlayerHealth <= 0)
    {
    transform.position = checkpointPosition;
    currentPlayerHealth = playerHealth;

    }
    }
    }


    Good Day!