Я сделал игру "Space Invader" и нашел способ сделать селектор игрока, но есть проблема, когда я создаю игру и играю в нее на своем мобильном телефоне и пытаюсь использовать селектор игрока для спрайта игрока остается по умолчанию для префаба и изменения спрайтов снаряда, и на них обоих ссылаются одинаково
вот код для выбора игрока:
using System;
using UnityEngine;
public class playerSelector : MonoBehaviour
{
[Header("Unlock Stuff")]
public GameObject Text;
public GameObject QuestionMark;
public GameObject RedDemon;
public GameObject GreenDemon;
//public GameObject Thridone;
//public GameObject Lastone;
[Header("Demons")]
[SerializeField] SpriteRenderer playerRender;
public SpriteRenderer tailRender;
[Header("Tails")]
public Sprite RedDemonTail;
public Sprite GreenDemonTail;
private Vector3 CharacterPoistion;
private int charcterInt = 1;
private SpriteRenderer QuestionMarkRender, RedDemonRender, GreenDemonRender, ThridRender; // LastRender;
GameSession game;
Sceneloader scene;
private void Awake()
{
game = FindObjectOfType<GameSession>();
scene = FindObjectOfType<Sceneloader>();
//for when the player dosent have the right score
QuestionMarkRender = QuestionMark.GetComponent<SpriteRenderer>();
//Getting position of the on screen position
CharacterPoistion = RedDemon.transform.position;
//Getting the sprite render of each sprite
RedDemonRender = RedDemon.GetComponent<SpriteRenderer>();
GreenDemonRender = GreenDemon.GetComponent<SpriteRenderer>();
//ThridRender = Thridone.GetComponent<SpriteRenderer>();
//LastRender = Lastone.GetComponent<SpriteRenderer>();
//Getting the transform of each Object
RedDemon.transform.position = CharacterPoistion;
GreenDemon.transform.position = CharacterPoistion;
//Thridone.transform.position = CharacterPoistion;
//Lastone.transform.position = CharacterPoistion;
//For when the game starts that the demon always starts red
playerRender.sprite = RedDemonRender.sprite;
tailRender.sprite = RedDemonTail;
}
public void NextPlayer()
{
switch (charcterInt)
{
case 1:
if(game.highscore == 999 )
{
RedDemonRender.enabled = false;
QuestionMarkRender.enabled = true;
Text.SetActive(true);
playerRender.sprite = RedDemonRender.sprite;
tailRender.sprite = RedDemonTail;
}
else
{
playerRender.sprite = GreenDemonRender.sprite;
tailRender.sprite = GreenDemonTail;
RedDemonRender.enabled = false;
GreenDemonRender.enabled = true;
charcterInt++;
}
break;
/*case 2:
GreenDemonRender.enabled = false;
ThridRender.enabled = true;
charcterInt++;
Debug.Log(charcterInt.ToString());
break;
case 3:
ThridRender.enabled = false;
LastRender.enabled = true;
charcterInt++;
Debug.Log(charcterInt.ToString());
break;
case 4:
LastRender.enabled = false;
FirstDemonRender.enabled = true;
charcterInt = 4;
Debug.Log(charcterInt.ToString());
RestInt();
break;
default:
RestInt();
break;
*/
}
}
public void LastPlayer()
{
switch (charcterInt)
{
case 2:
scene.ChosenSprite = "Red";
RedDemonRender.enabled = true;
GreenDemonRender.enabled = false;
playerRender.sprite = RedDemonRender.sprite;
tailRender.sprite = RedDemonTail;
charcterInt--;
break;
/*case 3:
scene.ChosenSprite = "Red";
charcterInt--;
break;
case 3:
ThridRender.enabled = true;
LastRender.enabled = false;
charcterInt--;
break;
case 4:
LastRender.enabled = true;
FirstDemonRender.enabled = false;
charcterInt--;
break;
default:
RestInt();
break;
*/
}
}
}
комментарии для других спрайтов, предназначенных для сделать