using System.Collections; using System.Collections.Generic; using System.Linq; using Unity.VisualScripting; using UnityEngine; using UnityEngine.SceneManagement; public class PlayerSwapScript : MonoBehaviour { [SerializeField] private Transform shapeContainer; [SerializeField] TimerTest timer; [SerializeField] TimerTest cooldownTimer; [SerializeField] Quills quills; [SerializeField] private GameObject tick4; [SerializeField] private GameObject transformationIcon; [SerializeField] private GameObject poofEffect; [SerializeField] private GameObject cameraIcon; public GameObject[] shapes; private int currentShapeIndex = 0; public static bool isHumanShape = true; public bool isReadyToShift = false; private float poofEffectDuration = 1f; private float poofEffectTimer = 0f; private bool isCooldown = false; public string[] lines; Dialogue dialogueScript; public bool dialogueHappened = false; public AudioSource src; public AudioClip AudioClip; private Collider originalCollider; private void Start() { originalCollider = GetComponent(); dialogueScript = GameObject.FindObjectOfType(); // Hide everything related to transformation initially timer.timerBar.SetActive(false); cooldownTimer.timerBar.SetActive(false); transformationIcon.SetActive(false); poofEffect.SetActive(false); cameraIcon.SetActive(false); } void Update() { // Show icons and trigger dialogue once quills are collected and transformation is unlocked if (isReadyToShift && quills.quillsCollected >= 5) { cameraIcon.SetActive(true); transformationIcon.SetActive(true); if (!dialogueHappened) { dialogueScript.lines = lines; dialogueScript.StartDialogue(); dialogueHappened = true; } } // Player presses Q to transform (only if ready, all quills collected, and not on cooldown) if (Input.GetKeyDown(KeyCode.Q) && isReadyToShift && quills.quillsCollected == 5 && cooldownTimer.Duration == 0) { ShiftShape(); } // Revert back if transformation time runs out if (!isHumanShape && timer.Duration == 0) { currentShapeIndex = 1; // Ensure switch to human (index 0 after increment) ShiftShape(); } // If cooldown ends, hide cooldown bar and reset if (isCooldown && cooldownTimer.Duration == 0) { isCooldown = false; cooldownTimer.timerBar.SetActive(false); } // Timer to auto-disable poof visual FX if (poofEffect.activeSelf) { poofEffectTimer += Time.deltaTime; if (poofEffectTimer >= poofEffectDuration) { poofEffect.SetActive(false); poofEffectTimer = 0f; } } } public void ShiftShape() { poofEffect.SetActive(true); poofEffectTimer = 0f; // Play transformation sound if (AudioClip != null) { Debug.Log("found sound"); src.clip = AudioClip; src.Play(); } // Save current position and rotation, destroy the old shape, and spawn the new one Vector3 currentPosition = transform.position; Quaternion currentRotation = transform.rotation; Destroy(shapeContainer.GetChild(0).gameObject); // Remove old shape shapeContainer.DetachChildren(); // Detach to avoid duplicates GameObject newShape = Instantiate(shapes[currentShapeIndex], currentPosition, currentRotation); newShape.transform.SetParent(shapeContainer); newShape.transform.localPosition = new Vector3(newShape.transform.localPosition.x, 0, newShape.transform.localPosition.z); currentShapeIndex++; if (currentShapeIndex >= shapes.Length) { currentShapeIndex = 0; // Loop back to human } isHumanShape = currentShapeIndex == 0; timer.timerBar.SetActive(!isHumanShape); // Show timer only when not human if (!isHumanShape) { timer.SetDuration(5).Begin(); // Start shape duration timer originalCollider.enabled = false; // Disable collider when not human } else { cooldownTimer.SetDuration(5).Begin(); // Begin cooldown when transforming back to human cooldownTimer.timerBar.SetActive(true); isCooldown = true; originalCollider.enabled = true; } tick4.SetActive(true); // Show UI feedback (checkmark?) } }