Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

silvakim

6
Posts
3
Topics
A member registered Nov 28, 2021

Recent community posts

I solve this isue. I used Debug.Log out of brace LOL. thank you for your kind reply!

private void Start()
{
StartCoroutine(SearchForInteraction());
}

I did like this. but it still exist. did I do rightly?

(1 edit)

thanks for reply. I did like this before.

private void Awake()
{
Instance = this;

}

Im coding with spacesurviver multiple kit. but there is null reference exception isue and no line renderer when player has distance  interactable task. 

public class TaskInteraction : MonoBehaviourPun

{

    [SerializeField] private float _range = 10.0f;

    private LineRenderer _lineRenderer;

    private Interactable _target;

    private void Awake()

    {

        if (!photonView.IsMine) { return; }

        _lineRenderer = GetComponent<LineRenderer>();

        StartCoroutine(SearchForInteraction());

    }

    private void Update()

    {

        if (!photonView.IsMine) { return; }

        if (_target != null )  

        {

            _lineRenderer.SetPosition(0, transform.position);

            _lineRenderer.SetPosition(1, _target.transform.position);

            Debug.Log("lineyes");

        }

        else

        {

            _lineRenderer.SetPosition(0, Vector3.zero);

            _lineRenderer.SetPosition(1, Vector3.zero);

            //Debug.Log("lineno");

        }

    }

    private IEnumerator SearchForInteraction()

    {

        while (true)

        {

            Interactable newTarget = null;

            Interactable[] interactionList = FindObjectsOfType<Interactable>();

            Debug.Log("searchtarget");

            UIControl.Instance.HasInteractable = false;    ---------------here's where null reference exception isue

            foreach (Interactable interactable in interactionList)

            {

                float distance = Vector3.Distance(transform.position, interactable.transform.position);

                if (distance > _range) { continue; }

                Debug.Log("searchdistance");

                // An interactible new target found

                newTarget = interactable;

                UIControl.Instance.HasInteractable = true;

                

                break;

            }

            // Reset the previous interactible, if any

            if (UIControl.Instance.CurrentInteractable != newTarget &&

                UIControl.Instance.CurrentInteractable != null)

                Debug.Log("searchnewtarget");

            {

                UIControl.Instance.CurrentInteractable.use(false); 

                

            }

            _target = newTarget;

            UIControl.Instance.CurrentInteractable = _target;

            yield return new WaitForSeconds(0.25f);

        }

    }

    

            

}

I applied PlayerInfo script and when I join room to test, there are some players with same colors. how can I fix it? There are 7 colors in my all player colors.

here is my player's color script


using UnityEngine;
using Photon.Pun;
using System.Collections.Generic;
using UnityEngine.Experimental.Rendering.Universal;
using UnityEngine.UI;

public class PlayerInfo : Photon.Pun.MonoBehaviourPun, IPunObservable
{

public int colorIndex;
public SpriteRenderer[] playerBody;

public List<Color> _allPlayerColors = new List<Color>();
// public Text _playerName;



public Color CurrentColor
{
get { return _allPlayerColors[colorIndex]; }
}

private void Awake()
{
if (photonView.IsMine)
{
colorIndex = Random.Range(0, _allPlayerColors.Count-1);
// _playerName.text = PhotonNetwork.LocalPlayer.NickName;

}

}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
// Owner.
stream.SendNext(colorIndex);

}
else
{
// Remote.
colorIndex = (int)stream.ReceiveNext();

}
}

private void Update()
{
foreach (SpriteRenderer playerPart in playerBody)
{
playerPart.color = _allPlayerColors[colorIndex];
}


}

I applied PlayerInfo script and when I join room to test, there are some players with same colors. how can I fix it? There are 7 colors in my all player colors.

here is my player's color script


using UnityEngine;
using Photon.Pun;
using System.Collections.Generic;
using UnityEngine.Experimental.Rendering.Universal;
using UnityEngine.UI;

public class PlayerInfo : Photon.Pun.MonoBehaviourPun, IPunObservable
{

public int colorIndex;
public SpriteRenderer[] playerBody;

public List<Color> _allPlayerColors = new List<Color>();
// public Text _playerName;



public Color CurrentColor
{
get { return _allPlayerColors[colorIndex]; }
}

private void Awake()
{
if (photonView.IsMine)
{
colorIndex = Random.Range(0, _allPlayerColors.Count-1);
// _playerName.text = PhotonNetwork.LocalPlayer.NickName;

}

}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
// Owner.
stream.SendNext(colorIndex);

}
else
{
// Remote.
colorIndex = (int)stream.ReceiveNext();

}
}

private void Update()
{
foreach (SpriteRenderer playerPart in playerBody)
{
playerPart.color = _allPlayerColors[colorIndex];
}


}