Question by
JokerJosh0001 · May 15 at 04:48 PM ·
buttonphotonbutton trigger eventsnetworkplayer
Texture change using a button with photon
at the moment i have a script that changes your players material when you press a button to a color but it can only change it to a solid color but i want to to make it change it to a texture, the only thing that ive got to work is it to change a objects texture but i want it to change the players texture, the reason why the other one wont work is because it changes a objects color that is in the hierachy but when you go into playmode, thats when the player gets spawned because thats how photon works.
heres the script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using UnityEngine.XR;
public class FeatherCollider : MonoBehaviour {
private float hapticWaitSeconds = 0.05f;
private void OnTriggerEnter(Collider other)
{
if (other.GetComponent<HandColliders>())
{
StartVibration(other.GetComponent<HandColliders>().isLeftHand, 0.7f, 0.15f);
buttonEnter(other.GetComponent<HandColliders>().isLeftHand);
}
}
public virtual void buttonEnter (bool isLeftHand)
{
if (Material)
{
}
else if (Color)
{
photonView.RPC("ChangePlayerMaterial", RpcTarget.All, new Vector3(this.colorValues.r,
this.colorValues.g, this.colorValues.b));
}
}
public virtual void buttonExit()
{
}
private NetworkPlayerSpawner networkPlayerSpawner;
private PhotonView photonView;
public Color colorValues;
public Material materialValues;
public bool Material;
public bool Color;
private void Start()
{
networkPlayerSpawner =
GameObject.Find("/NetworkManager").GetComponent<NetworkPlayerSpawner>();
}
private void Update()
{
if (PhotonNetwork.InRoom)
if (networkPlayerSpawner.isPlayerSpwaned)
{
// networkSManager.spawnedPlayerPrefab.GetComponent<PhotonView>();
if (photonView == null)
{
photonView =
networkPlayerSpawner.spawnedPlayerPrefab.GetComponent<PhotonView>();
}
}
}
public void StartVibration(bool forLeftController, float amplitude, float duration)
{
base.StartCoroutine(this.HapticPulses(forLeftController, amplitude, duration));
}
// Token: 0x06000315 RID: 789 RVA: 0x00016512 File Offset: 0x00014712
private IEnumerator HapticPulses(bool forLeftController, float amplitude, float duration)
{
float startTime = Time.time;
uint channel = 0U;
InputDevice device;
if (forLeftController)
{
device = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
}
else
{
device = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
}
while (Time.time < startTime + duration)
{
device.SendHapticImpulse(channel, amplitude, this.hapticWaitSeconds);
yield return new WaitForSeconds(this.hapticWaitSeconds * 0.9f);
}
yield break;
}
},
Comment