Hello there,
In my car game, I assign to the car according to the selected cover and save it. I’m having a problem with my test scenario;
1-) The player selects a cover in the garage with his tool and changes it.
2-) In the same scene, he returns to the main menu and selects another vehicle.
3-) When the second vehicle of its choice wants to change the cover, THE COVER of THE FIRST VEHICLE CHANGES ! No change(no new load cover) for the second vehicle.
All operations are done in one scene and I try to manage it with two scripts;
GeneralGameManager.cs - On the MainMenu
LoadCover.cs - Attached to each cars
This debug updates correctly when I select other car for _currentCoverID and GCurrentCarID;
Debug.Log(“Load Cover:”+ _currentCoverID+GeneralGameManager.instance.GCurrentCarID);
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GeneralGameManager : MonoBehaviour
{
#region Singleton
private static GeneralGameManager _Instance;
public static GeneralGameManager instance
{
get
{
if (_Instance == null)
_Instance = GameObject.FindObjectOfType<GeneralGameManager>();
return _Instance;
}
}
#endregion
public Texture[] CarCover;
public int currentCoverID;
public int GCurrentCarID;
void Start()
{
DontDestroyOnLoad(gameObject);
}
public void CoverSelect(int _cov)
{
if (GCurrentCarID == 0 || GCurrentCarID == 1 || GCurrentCarID == 2 || GCurrentCarID == 3)
{
Debug.Log("GCurrentID: " + GCurrentCarID.ToString());
currentCoverID = _cov;
LoadCover.instance.m_Renderer.sharedMaterial.SetTexture("_MainTex", CarCover[currentCoverID]);
PlayerPrefs.SetInt("currentCoverID" + GCurrentCarID, currentCoverID);
LoadCover.instance.LoadtheCover();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoadCover : MonoBehaviour
{
#region Singleton
private static LoadCover _Instance;
public static LoadCover instance
{
get
{
if (_Instance == null)
_Instance = GameObject.FindObjectOfType<LoadCover>();
return _Instance;
}
}
#endregion
public Renderer m_Renderer;
public int _currentCoverID;
//public int _closeoverlap;
// Start is called before the first frame update
public void Start()
{
m_Renderer = GetComponent<Renderer>();
StartCoroutine(CoverStarting());
}
IEnumerator CoverStarting()
{
yield return new WaitForEndOfFrame();
LoadtheCover();
}
public void LoadtheCover()
{
if (GeneralGameManager.instance.GCurrentCarID == 0 || GeneralGameManager.instance.GCurrentCarID == 1 || GeneralGameManager.instance.GCurrentCarID == 2 || GeneralGameManager.instance.GCurrentCarID == 3)
{
m_Renderer = GetComponent<Renderer>();
m_Renderer = GetComponent<Renderer>();
_currentCoverID = PlayerPrefs.GetInt("currentCoverID"+"||" + GeneralGameManager.instance.GCurrentCarID, 1511);
m_Renderer.sharedMaterial.SetTexture("_MainTex", GeneralGameManager.instance.CarCover[_currentCoverID]);
Debug.Log("Load Cover:"+ _currentCoverID+"||"+GeneralGameManager.instance.GCurrentCarID);
}
}
}