#NEED HELP WITH SETACTIVIE (I AM FOLLOWING CODE MONKEY'S COURSE)

1 messages · Page 1 of 1 (latest)

lucid quartz
#

[]cb

trim raftBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

woeful inlet
#

i've sent the text files, that wont work ?

#

it looks neat

lucid quartz
#

I'm on mobile so they don't show

#

And I'm not downloading random files

woeful inlet
#

Help me out man 🥲🥲 it's just code

#

Straight Outta unity 😭😭

#

Will you help me once you're on your pc please ?

viral shale
woeful inlet
#
using System.Collections.Generic;
using UnityEngine;

public class SelectedCounterVisual : MonoBehaviour
{
    // singleton pattern 

    [SerializeField] private ClearCounter clearCounter;
    [SerializeField] private GameObject visualGameObject;
    private void Start()
    {
        Player.Instance.OnSelectedCounterChanged += Player_OnSelectedCounterChanged;
    }

    private void Player_OnSelectedCounterChanged(object sender, Player.OnSelectedCounterChangedEventArgs e)
    {
        if (e.selectedCounter == clearCounter)
        {
            print("trynna show !! ");
            show();
        }
        else
        {
            hide();
        }

    }

    public void show()
    {
        visualGameObject.SetActive(true);
    }
    private void hide()
    {
        visualGameObject.SetActive(false);
    }
}
#
using System.Collections.Generic;
using UnityEngine;

public class ClearCounter : MonoBehaviour
{
    public void Interact ()
    {
        Debug.Log("interect");
    }
}
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameInput : MonoBehaviour
{
    public event EventHandler onInteractAction;
    
    private PlayerInputActions playerInputActions;
    public void Awake()
    {   
        

        playerInputActions  = new PlayerInputActions();
        playerInputActions.Player.Enable();


       
        playerInputActions.Player.Interact.performed += Interact_performed;
    }

    private void Interact_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
    {

        print("i pressed E");

        onInteractAction?.Invoke(this, EventArgs.Empty); // does excatly what the code below does !!  
      
        
        /*  alternate method 
            if (onInteractAction != null)
        {
            onInteractAction(this, EventArgs.Empty);   // checking if there are any subs, if there aint any we wont call the interaction to avoid null reference exception 
        } 
        */

    }

    public Vector2 GetMovementVectorNormalized()
    {


        Vector2 inputVector = playerInputActions.Player.Move.ReadValue<Vector2>(); 
        

        inputVector = inputVector.normalized;
        return inputVector;
    }
}
woeful inlet
#

nevermind, i fixed it

ionic wagon
#

want to share what the issue was ?

woeful inlet
#

it was a simple logic error, explained to me by a friend

#

so here is how it went

#

if (Physics.Raycast(transform.position, lastInteracDir, out RaycastHit raycastHit, interactionDistance, countersLayerMask))
{
if (raycastHit.transform.TryGetComponent(out ClearCounter clearCounter))

        {

// the component on the hit object is clearCounter, the one you get from out-thing above
if (clearCounter != selectedCounter)
{
//you're passing here not the clearCounter you just obtained, but selectedCounter, which is just for storing the last one you got
SetSelectedCounter(selectedCounter);
}
}
else
{
SetSelectedCounter(null);
}
}
else
{
SetSelectedCounter(null);
}

#

so instead of SetSelectedCounter(selectedCounter) it should be SetSelectedCounter(clearCounter)

ionic wagon
#

thanks for sharing - repeating the explanation can be a useful way of helping retain the information, and also helps anyone who happens to run into this here find out in case they run into the same issue. CodeMonkey seems to change that line at 2h57m36s in the video.
https://www.youtube.com/watch?v=AmGSEH7QcDg&t=10399s

💬 This was a ton of work to make so I really hope it helps you in your game dev journey! Hit the Like button!
🌍 Course Website with Downloadable Assets, FAQ, Related Videos https://cmonkey.co/freecourse
🎮 Play the game on Steam! https://cmonkey.co/kitchenchaos
❤ IF you can afford it you can get the paid ad-free version https://cmonkey.co/kitchen...

▶ Play video
lucid quartz
#

Please don't delete your original message

#

Then this thread is of little use to others