SetDataSystem
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;
public class SetDataSystem : MonoBehaviour
{
private PhotonView m_photonview;
public GameObject[] TriggerPos; // The list of triggers for movement and add ID automatically
public GameObject Player;
public float PlayerMovementTime; // When player wants to move by this script, It will be speed of lerp (smooth movement)
public int ID;
public float dist; // The distance between player and trigger object (For manage the lerp process)
internal bool PosActivator = false;
private void Awake()
{
m_photonview = GetComponent(); //Make sure that your object needs to have Photonview component
for (int i = 0; i < TriggerPos.Length; i++)
{
TriggerPos[i].GetComponent().ID = i;
TriggerPos[i].name = "";
TriggerPos[i].name = "Trigger" + i;
}
}
private void Start()
{
Invoke("PosActivator",4.2f);
}
void StartPosSet()
{
PosActivator = true;
}
public void CheckCurrentPos(int TargetID, string objname)
{
m_photonview.RPC("RPC_Pos", RpcTarget.All, TargetID, objname);
}
[PunRPC]
private void RPC_Pos(int TargetID, string objname)
{
ID = TargetID;
GameObject obj = GameObject.Find(objname);
Player = obj;
print(TargetID + objname);
}
private void Update()
{
if (PosActivator == true)
{
if (TriggerPos[ID] != null && Player != null)
{
dist = Vector3.Distance(Player.transform.position,TriggerPos[ID].transform.position);
}
if (dist > 0.1f)
{
Player.transform.position = Vector3.Lerp(Player.transform.position,TriggerPos[ID].transform.position,PlayerMovementTime*Time.deltaTime);
print("Lerping !!!");
}
}
}
}