Friday, April 18, 2025
spot_img

unity – Character choice display to decide on what character hundreds in subsequent scene


I’m engaged on the character choice display for my recreation. I would like it in order that, when the participant clicks on the choose button, the code checks if the imagecollection within the charactermanger is 0, then hundreds the primary character and so forth.

Listed here are my three scripts:

Character Change

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class CharacterChange : MonoBehaviour
{
    public static CharacterChange occasion;

    public static GameObject player1dub;
    public GameObject Participant;
    public GameObject orangeShown;
    public GameObject grapesShown;
    public GameObject appleShown;
    public GameObject bananaShown;
    public Rework playerTransform;
    public Rework orangeTransform;
    public Rework grapesTransform;
    public Rework appleTransform;
    public Rework bananaTransform;
    public Rework orangeHitPoint;
    public Rework grapesHitPoint;
    public Rework remyHitPoint;
    public Rework appleHitPoint;
    public Rework bananaHitPoint;
    public Rework secondplayerhit;
    public Rework orangeCameraMovement;
    public Rework grapesCameraMovement;
    public Rework remyCameraMovement;
    public Rework appleCameraMovement;
    public Rework bananaCameraMovement;
    public Rework 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 Begin()
    {
        playerMotionScript = GetComponentInParent();
        cameraManagerScript = FindObjectOfType();
        gunScript = FindObjectOfType();
        scalingScript = GetComponent();
        myAnimator = GetComponent();
        timerscript = FindObjectOfType();
        sensorScript = GetComponent();
        startScale = playerMotionScript.selectedPlayer.rework.localScale;
    }

    public IEnumerator RemyChangeEnumerator()
    {
        if (playerMotionScript.selectedPlayer != Participant)
        {
            playerMotionScript.selectedPlayer.SetActive(false);
            elapsedTime += Time.deltaTime;
            float full = elapsedTime / timeDuration;
            playerMotionScript.selectedPlayer.rework.localScale = Vector3.Lerp(endScale, startScale, full);
            playerTransform.place = playerMotionScript.selectedPlayer.rework.place;
            Participant.SetActive(true);
            playerMotionScript.allHitPoints = remyHitPoint;
            playerMotionScript.selectedPlayer = Participant;
            playerMotionScript.HandlePlayerChange();
            cameraManagerScript.SetCameraMovement(remyCameraMovement);
            yield return null;
        }
    }

    personal void OnTriggerEnter(Collider different)
    {
        Destroy(different.gameObject);

        if (different.gameObject.tag == "OrangeCollision" && playerMotionScript.selectedPlayer != orangeShown)
        {
            ChangeCharacter(orangeShown, orangeTransform, orangeHitPoint, orangeCameraMovement);
        }
        else if (different.gameObject.tag == "GrapesCollision" && playerMotionScript.selectedPlayer != grapesShown)
        {
            ChangeCharacter(grapesShown, grapesTransform, grapesHitPoint, grapesCameraMovement);
        }
        else if (different.gameObject.tag == "AppleCollision" && playerMotionScript.selectedPlayer != appleShown)
        {
            ChangeCharacter(appleShown, appleTransform, appleHitPoint, appleCameraMovement);
        }
        else if (different.gameObject.tag == "BananaCollision" && playerMotionScript.selectedPlayer != bananaShown)
        {
            ChangeCharacter(bananaShown, bananaTransform, bananaHitPoint, bananaCameraMovement);
        }
    }

    personal void ChangeCharacter(GameObject newCharacter, Rework newTransform, Rework newHitPoint, Rework newCameraMovement)
    {
        playerMotionScript.selectedPlayer.SetActive(false);
        elapsedTime += Time.deltaTime;
        float full = elapsedTime / timeDuration;
        playerMotionScript.selectedPlayer.rework.localScale = Vector3.Lerp(endScale, startScale, full);

        newTransform.place = playerMotionScript.selectedPlayer.rework.place;
        newCharacter.SetActive(true);

        playerMotionScript.allHitPoints = newHitPoint;
        playerMotionScript.selectedPlayer = newCharacter;
        playerMotionScript.HandlePlayerChange();

        cameraManagerScript.SetCameraMovement(newCameraMovement);

        timerscript.linewait = 5;
        timerscript.timerBar.fillAmount = 1;

        newCharacter.GetComponent().scale = true;
    }
}

SelectButton

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UI;

public class SelectButton : MonoBehaviour
{
    public Button selectButton;
    public GameObject[] characterPrefabs;
    public CharactersManager managerScript;
    // Begin is known as earlier than the primary body replace
    void Begin()
    {
    }

    //Replace is known as as soon as per body
    void Replace()
    {
        
    }

    public void CharactersSelect()
    {
        if (managerScript.imageCollection[0])
        {
            Debug.Log("Participant is " + CharacterChange.occasion.Participant);
        }
    }
}

CharacterManager

utilizing UnityEngine;
utilizing UnityEngine.UI;

public class CharactersManager : MonoBehaviour
{
    public Sprite[] imageCollection;
    public Picture displayImage;
    personal int currentImageIndex = 0;
    public SelectButton selectScript;

    void Begin()
    {
        if (imageCollection.Size > 0)
        {
            displayImage.sprite = imageCollection[currentImageIndex];
        }
    }

    public void OnNextButtonClick()
    {
        if (imageCollection.Size > 1)
        {
            currentImageIndex = (currentImageIndex + 1) % imageCollection.Size;
            displayImage.sprite = imageCollection[currentImageIndex];
        }
    }
}

So how can I make the character choice work?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles