Freezin

Hi everyone,

I ran into troblue trying to use the freeze position feature in unity
here’s the code

this is the code that tells the program which feature of the game to use for the player

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Stick_Choice : MonoBehaviour
{
    // Start is called before the first frame update
   
   

    public void ChooseStickOption()
    {
       

        if (Input.GetKey(KeyCode.R))
        {
            leftPlayerStickNum++;
            leftPlayerStickNum %= 2;
        }
        if (Input.GetKey(KeyCode.T))
        {
            rightPlayerStickNum++;
            rightPlayerStickNum %= 2;
        }
    }

    public int GetLeftPlayerSitckNum()
    {
        return leftPlayerStickNum;
    }

    public int GetRightPlayerSitckNum()
    {   
        rightPlayerStickNum += 2;
        return rightPlayerStickNum;
    }

    private int leftPlayerStickNum = 0;
    private int rightPlayerStickNum = 0;





    void Update()
    {
        ChooseStickOption();  
    }
}

this code is where the previous code sends the information to.


```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enable_Disable : MonoBehaviour
{

    public GameObject NeturalPos;
    // forward slash /
    public GameObject UpwardPos;

    // \ the back slasj
    public GameObject DianolUp;

    public GameObject StickPos;

    public GameObject ChargerPos;

    [SerializeField] private Rigidbody PaddleBody;
    // Start is called before the first frame update
    public bool isRotateKeyDown;


    [SerializeField] private Stick_Choice SetStickOption;
    [SerializeField] private Stick_Applyer GetStickOption;

   
  
   
   


    //this will be used to record the paddles original size
    void Start()
    {
        PaddleBody = GetComponent<Rigidbody>();
if(SetStickOption==null)
        {
            SetStickOption = new Stick_Choice();       
        }
        if (GetStickOption == null)
        {
            GetStickOption = new Stick_Applyer();
        }


    }

private void Update()
    {

if (InputManager.LPaddle_Stick())
        {
            GetStickOption.StickApplyerFunction(SetStickOption.GetLeftPlayerSitckNum(), PaddleBody);
            Debug.Log("worked");
}
}//end of update

once the button is pressed then Enable_Disable sends the code to here 

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Stick_Applyer : MonoBehaviour
{


   
    public void FreezeCountdown(Rigidbody stopMovement)
    {
        stopMovement = GetComponent<Rigidbody>();        
stopMovement.constraints = RigidbodyConstraints.FreezePositionZ;

        
  

    public void StickApplyerFunction(int choose, Rigidbody givenGameObj)
    {
        switch(choose)
        {
            case 0:
                Debug.Log("stick1_left_player: workd");
                FreezeCountdown(givenGameObj);
                ResetTimer();
                break;
            case 1:
                Debug.Log("stick2_left_player: workd");
                break;
            case 2:
                Debug.Log("stick1_right_player: workd");
                break;
            case 3:
                Debug.Log("stick2_right_player: workd");
                break;

        }
    }

so in the end the question is
why is this not working?

Great question!

My first question back, “Is the freeze code even running?”

Put a Debug.Log() at every point where something isn’t working and find out first: is this code even getting executed?

It makes no sense even trying to fix code that isn’t being executed!

What @Kurt-Dekker said plus take a look at this file, because you are missing multiple **}** in this file. I don’t know if you just messed up your post or the original file looks like this, because then you must have some errors in the console as well.