Amboir
Amboir
CC#
Created by Amboir on 1/20/2024 in #help
im creating a game in unity for school, and need some help with a script error
my code so far
6 replies
CC#
Created by Amboir on 1/20/2024 in #help
im creating a game in unity for school, and need some help with a script error
using System.Collections; using System.Collections.Generic; using UnityEngine; public class FreezeCharacter : MonoBehaviour { private bool isFrozen = false; private Rigidbody characterRigidbody; private YourCharacterMovementScript movementScript; void Start() { characterRigidbody = GetComponent<Rigidbody>(); movementScript = GetComponent<YourCharacterMovementScript>(); } void Update() { if (Input.GetKeyDown(KeyCode.P)) { ToggleFreeze(); } } void ToggleFreeze() { isFrozen = !isFrozen; if (isFrozen) { FreezeCharacterInPlace(); } else { UnfreezeCharacter(); } } void FreezeCharacterInPlace() { if (movementScript != null) { movementScript.enabled = false; } if (characterRigidbody != null) { characterRigidbody.velocity = Vector3.zero; characterRigidbody.angularVelocity = Vector3.zero; characterRigidbody.isKinematic = true; } } void UnfreezeCharacter() { if (movementScript != null) { movementScript.enabled = true; } if (characterRigidbody != null) { characterRigidbody.isKinematic = false; } } }
6 replies