0
\$\begingroup\$

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;
    }
}
\$\endgroup\$
5
  • \$\begingroup\$ This question is similar to: Character selection screen to choose what character loads in next scene. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. \$\endgroup\$
    – Zibelas
    Commented Jul 17 at 6:05
  • \$\begingroup\$ It's not at all clear to me what help you need with these two scripts. What behaviour do you observe with your current code, and how does it differ from what you want? What is the next step you need help with? \$\endgroup\$
    – DMGregory
    Commented Jul 17 at 10:31
  • \$\begingroup\$ Please do not post duplicate questions. Please go back and edit the previous version of this question to explain what the problem is - what's currently happening and what you want to happen. \$\endgroup\$
    – Kevin
    Commented Jul 17 at 22:44
  • \$\begingroup\$ Sorry to all of you i want some other implementaion i want it like this that there is the image for selecting character but on which image it click then select that player in which is the array of the player select the player acccording to the image array and also i only want the player variable in the character change \$\endgroup\$
    – Jano Wazir
    Commented Jul 18 at 1:33
  • \$\begingroup\$ Please edit your existing question to say that. Explain what is not working the way you want with the current code, and what you mean by "I only want the player variable in the character change". \$\endgroup\$
    – DMGregory
    Commented Jul 18 at 12:24

0

Browse other questions tagged .