Hi to everyone i want to make the character selection screen the following 2 are scripts
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SelectButton : MonoBehaviour
{
public Button selectButton;
public GameObject[] characterPrefabs;
public CharactersManager managerScript;
// Start is called before the first frame update
void Start()
{
}
//Update is called once per frame
void Update()
{
}
public void CharactersSelect()
{
if (managerScript.imageCollection[0])
{
Debug.Log("Player is " + CharacterChange.instance.Player);
}
}
}
CharacterChange Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterChange : MonoBehaviour
{
public static CharacterChange instance;
public static GameObject player1dub;
public GameObject Player;
public GameObject orangeShown;
public GameObject grapesShown;
public GameObject appleShown;
public GameObject bananaShown;
public Transform playerTransform;
public Transform orangeTransform;
public Transform grapesTransform;
public Transform appleTransform;
public Transform bananaTransform;
public Transform orangeHitPoint;
public Transform grapesHitPoint;
public Transform remyHitPoint;
public Transform appleHitPoint;
public Transform bananaHitPoint;
public Transform secondplayerhit;
public Transform orangeCameraMovement;
public Transform grapesCameraMovement;
public Transform remyCameraMovement;
public Transform appleCameraMovement;
public Transform bananaCameraMovement;
public Transform secondplayercamera;
PlayerMotion playerMotionScript;
CameraManager cameraManagerScript;
Gun gunScript;
Animator myAnimator;
Timer timerscript;
ScalingOfModels scalingScript;
AiSensor sensorScript;
public bool scaleBool;
public bool remyScaleBool;
public Vector3 endScale;
public Vector3 startScale;
public float timeDuration;
public float elapsedTime;
void Start()
{
playerMotionScript = GetComponentInParent<PlayerMotion>();
cameraManagerScript = FindObjectOfType<CameraManager>();
gunScript = FindObjectOfType<Gun>();
scalingScript = GetComponent<ScalingOfModels>();
myAnimator = GetComponent<Animator>();
timerscript = FindObjectOfType<Timer>();
sensorScript = GetComponent<AiSensor>();
startScale = playerMotionScript.selectedPlayer.transform.localScale;
}
public IEnumerator RemyChangeEnumerator()
{
if (playerMotionScript.selectedPlayer != Player)
{
playerMotionScript.selectedPlayer.SetActive(false);
elapsedTime += Time.deltaTime;
float complete = elapsedTime / timeDuration;
playerMotionScript.selectedPlayer.transform.localScale = Vector3.Lerp(endScale, startScale, complete);
playerTransform.position = playerMotionScript.selectedPlayer.transform.position;
Player.SetActive(true);
playerMotionScript.allHitPoints = remyHitPoint;
playerMotionScript.selectedPlayer = Player;
playerMotionScript.HandlePlayerChange();
cameraManagerScript.SetCameraMovement(remyCameraMovement);
yield return null;
}
}
private void OnTriggerEnter(Collider other)
{
Destroy(other.gameObject);
if (other.gameObject.tag == "OrangeCollision" && playerMotionScript.selectedPlayer != orangeShown)
{
ChangeCharacter(orangeShown, orangeTransform, orangeHitPoint, orangeCameraMovement);
}
else if (other.gameObject.tag == "GrapesCollision" && playerMotionScript.selectedPlayer != grapesShown)
{
ChangeCharacter(grapesShown, grapesTransform, grapesHitPoint, grapesCameraMovement);
}
else if (other.gameObject.tag == "AppleCollision" && playerMotionScript.selectedPlayer != appleShown)
{
ChangeCharacter(appleShown, appleTransform, appleHitPoint, appleCameraMovement);
}
else if (other.gameObject.tag == "BananaCollision" && playerMotionScript.selectedPlayer != bananaShown)
{
ChangeCharacter(bananaShown, bananaTransform, bananaHitPoint, bananaCameraMovement);
}
}
private void ChangeCharacter(GameObject newCharacter, Transform newTransform, Transform newHitPoint, Transform newCameraMovement)
{
playerMotionScript.selectedPlayer.SetActive(false);
elapsedTime += Time.deltaTime;
float complete = elapsedTime / timeDuration;
playerMotionScript.selectedPlayer.transform.localScale = Vector3.Lerp(endScale, startScale, complete);
newTransform.position = playerMotionScript.selectedPlayer.transform.position;
newCharacter.SetActive(true);
playerMotionScript.allHitPoints = newHitPoint;
playerMotionScript.selectedPlayer = newCharacter;
playerMotionScript.HandlePlayerChange();
cameraManagerScript.SetCameraMovement(newCameraMovement);
timerscript.linewait = 5;
timerscript.timerBar.fillAmount = 1;
newCharacter.GetComponent<ScalingOfModels>().scale = true;
}
}