#💻┃code-beginner

1 messages · Page 254 of 1

shadow rain
#

TYTYTY

lapis yew
#

if(returnType == DerivedClass1)

do this

rich adder
#

You probably want to learn object pooling at some point, if you're instantiating thousands of objects there is a performance implication when creating so many objects

hidden sleet
#

In this situation I don't think it does. I want to add a new inventoryItem, which is essentially just an inventory slot, with an item and quantity. But the abstract class doesn't have a field for Item, only the derived ones do since that slot can be either an itemSO or a structureSerialised

wild fox
#

my unity crashes when my gameobject dies, how do i know what's the issue? there are no errors in VS

sage mirage
#

Hey, guys! Can you help me please with Null Reference that I am dealing with? So, I am making a flappy bird game and whenever my player enters the collider of the other object(gem) it disappears and my particle is being instantiated with object pooling method. So, what's happening basically is that instead of returning my gem particle game object back to its pool for one reason I am destroying it or something but as I see on my code I don't have any Destroy() method or something that destroys the object I have replaced everything. Check what is happening in the video below.

polar acorn
timber tide
#
    public bool DoTypeStuff(Item item)
    {
        if (item is Weapon weapon)
        {
          //weapon.Attack();
        }

        else if (item is Potion potion)
        {
          //potion.Drink();
        }
    }```
Bad example as this could be like a polymorphic Use() method maybe but you get the idea
lapis yew
wild fox
polar acorn
rich adder
#

clearly something is destroying

sage mirage
#

Can I make a thread please to provide all the information needed?

slender nymph
rich adder
#

Ahh those are particles nvm digi is prob right

lapis yew
#

ah, okay

hidden sleet
#

SO Inventory with an abstract class as it's container type

sage mirage
#

Null Reference Exception Error

#

@polar acorn Hey mate! Join the thread to discuss the issue if you are available.

sage mirage
#

It is not set to destroy on completion I think but it is a particle system

lost anvil
rich adder
#

log the current patrol point etc.

lost anvil
#

i am

#

new dest when he reaches the point and finds a new destination and it logs the new patrol point to go to

past cloud
#

Anyone know how to fix vscode not having intellisense when trying to write my unity scripts?

rich adder
eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

rich adder
#

follow these instructions ^^

past cloud
#

twice

rich adder
#

can you show the External Tools window in Unity

lost anvil
rich adder
# past cloud

Uncheck the last to second check mark and click regen, clock vs first. Then open script again from unity

#

check Output window for any errors

rich adder
lost anvil
#

i think its the distance logic maybe? like the distance between points, but im not sure because occasionally it works, but for other points it doesnt like that one

rich adder
lost anvil
#

its 1

shadow rain
#

how would i reference the clones i made? for a rubber or an eraser

rich adder
rich adder
lost anvil
rich adder
#

just because it may not for your case, but stopp distance can matter a lot

lost anvil
#

yeah thats what i mean for this it doesnt matter

rich adder
#

Have you looked at the gizmos of agent during playmode ?

#

see whats happening

lost anvil
#

all the gizmos i can see are the ones on the video

rich adder
#

do you see the red circle gizmo around your Point ?

lost anvil
#

not loading

rich adder
#

discord is taking a shit h/o

lost anvil
#

fair

#

ik what your talking about i think

rich adder
lost anvil
#

that?

#

🤣

rich adder
#

wtf is good with attachments rn lol

wild fox
#

i can't see my spawned hovertank in the scene, even tho i can see that it's spawned in the console

#
using Core.Utilities;
using JetBrains.Annotations;
using System;
using System.Collections;
using System.Collections.Generic;
using TowerDefense.Agents;
using TowerDefense.Agents.Data;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.AI;

public class NewEnemy : MonoBehaviour
{
    [SerializeField] private GameObject myHoverTank;
    private void Start()
    {
        DamageableBehaviour damageableBehaviour = GetComponent<DamageableBehaviour>();
        damageableBehaviour.died += DamageableBehaviour_died;
    }

    private void DamageableBehaviour_died(DamageableBehaviour obj)
    {
        Destroy(obj);
        Debug.Log($"{obj} destroyed");
        GameObject newEnemy = Instantiate(myHoverTank, transform.position, Quaternion.identity);
        Debug.Log(newEnemy.name);
        newEnemy.GetComponent<NavMeshAgent>().enabled = true;
    }
}```
lost anvil
rich adder
lost anvil
#

ye

rich adder
#

the red circle is the agent current destination

lost anvil
#

but thats only supposed to happen through the distance check

#

like the switch of points

rich adder
#

well clearly its happening earlier

lost anvil
#

and im assuming it does but it happens too far

rich adder
#

so something is flawed in logic

lost anvil
#

the only place im referencing OnReachPPoint(); is in the distance check so idk what it is

rich adder
shadow rain
#

!code

eternal falconBOT
shadow rain
#
       void OnTriggerEnter2D(Collider2D other)
        {
            if (other.tag == "Paint")
            {
                if((Input.GetMouseButton(1))) Destroy(other);
            }
        }
#

i tried this

rich adder
lost anvil
#

on points?

rich adder
rich adder
lost anvil
#

the ai you mean

rich adder
#

cause you have it Set to Center mode

#

sure yea

lost anvil
#

ok

rich adder
#

Pivot on Center mode can be misleading

lost anvil
#

pivot points are fine

rich adder
#

make sure its set to Pivot Local

lost anvil
#

ye

#

😴

rich adder
#

and the pivot is where the enemy is

lost anvil
#

ye

shadow rain
rich adder
#

start debugging that make sure its correct numbers

wild fox
rich adder
wild fox
#

it's a prefab

rich adder
#

irrelevant

wild fox
#

but yes, it does have few scripts

rich adder
#

and does one of the scripts have something in Start/Awake ?

lost anvil
#

mate

#

its just spam setting new points

rich adder
#

anyway this is why changing agen stopping distance didnt help

#

your Distance is still fixed to 1
are you sure that is the correct distance you want?

lost anvil
#

like, everytime he is done waiting at a patrol point, the script finds a new point multiple times before he moves making his movement a bit laggy and maybe offputting the transform.position of the point he wants to go to

lost anvil
#

just stuck it into a variable

rich adder
#

in the code?

lost anvil
#

yeah

#

(Vector3.Distance(ai.transform.position, selectedPoint.position) <= pointDistance)

rich adder
#

and you also debugged ditance?

#

var distance = Vector3.Distance(ai.transform.position, selectedPoint.position);

lost anvil
#

no ill do that

rich adder
#

I think 1 unit may be too large

#

but if you changed it then somehting else

lost anvil
#

alright ill take a gander with this distance debug

short hazel
#

Note that if the variable is serialized in the Inspector, modifying its value in the initializer code does nothing, as the Inspector takes precedence over values set in the code

wild fox
#

script used to work fine before i made few changes an hour ago or so

#

and i dont think i made any major changes

rich adder
#

you're doing a whole lot of assumptions without testing the basics

wild fox
#

and that script acts weird in some other levels

rich adder
#

Ie if you have certain Nulls in Start/Awake then your object will disable itself

wild fox
rich adder
#

thats too much committment lol

#

its an easy thing to check mate, the object you instantiate check its script on Awake/Start

#

share those two scripts if you want !code

eternal falconBOT
wild fox
#

well, i tried using SetActive(true) and it spawned now

rich adder
#

unless your prefab was saved as Inactive

#

then it would explain it

#

otherwise you're putting a bandaid on a bleeding gash

wild fox
#

you mean this right?

#

yes it was inactive by default

shadow rain
#

!code

eternal falconBOT
shadow rain
#
// Your code here
    void OnTriggerEnter2D(Collider2D other)
        {
            if (other.tag == "Paint" && ((Input.GetMouseButton(1))))
            {
                Destroy(other);
            }
        }
#

idrk what else to do

rich adder
rich adder
polar acorn
wild fox
#

without the setactive()

shadow rain
rich adder
#

what triggers what

shadow rain
#

it triggers when collided

#

with an object

#

or the object u said

rich adder
#

well with a physics object

#

triggers dont collide, they Trigger lol

#

they aren't solid

#

anyway doing what ur doing is prob wrong for an erasing method

shadow rain
#

ok : (

#

what else could i do?

rich adder
#

Like I said earlier you need to select them with the mouse prob using a raycast or something

shadow rain
#

hmmm ok

rich adder
#

but do they have colliders?

shadow rain
#

ye

rich adder
# shadow rain ye

alr well use a mouseraycast and look for collider with Paint tag or whatever

rich adder
shadow rain
#

ok

queen adder
#

ISO or ANSI for coding?

rich adder
queen adder
rich adder
#

Ohhh..use whatever you're used to lol

#

Im in US so I use ANSI

#

using \| next to Z key would be weird af for me

rotund hull
#

why is this happening

wintry quarry
#

no "what" here?

polar acorn
rotund hull
#

world space

rotund hull
wintry quarry
#

they're probably not in front of the camera

polar acorn
rotund hull
#

they are

#

and when the player colides with them they reappaer

rich adder
#

you checked their Z positions

polar acorn
rotund hull
polar acorn
#

So show that code

rotund hull
#

!code

eternal falconBOT
rotund hull
#

but this is also happening to the ground

#

i have a ground object and you can't see it until the player colides with the flying boxs

#

but you can colide with the ground

polar acorn
#

Okay, so, considering this code teleports the player to this object's position and then moves the camera to follow them, that lends further evidence to the "They are out of view of the camera" theory

#

What are the positions of the camera and the objects?

rotund hull
polar acorn
#

I mean what are the positions of the camera, and the objects that are not visible

rotund hull
#

ohhhhhh

#

the cams pos is 1 on the z

rich adder
#

objects to be infront they have to be greater Z value from the camera Z

polar acorn
rotund hull
#

no just the cam

#

the others are 0 on the z

rich adder
#

so the camera is infront of them

rotund hull
#

yes

#

but only 1

rich adder
#

do you see the problem now

polar acorn
#

So then they aren't actually in front of the camera

#

They're behind it

rotund hull
#

yeah is it suposed to be like

#

that

polar acorn
#

So then what's the problem

rotund hull
#

let me try somehting with the code

rotund hull
rich egret
#

!code

eternal falconBOT
rich egret
#

Anyone have an idea why this is happening? If you need more details I will

polar acorn
rich egret
polar acorn
#

So it's doing what you told it to do

rich egret
polar acorn
rich egret
polar acorn
#

category is "Weapon" so it runs the weapon branch

#

and since there's two things in the weapon list, it won't add another

rich egret
polar acorn
#

That log only runs when category is "Weapon"

#

If you're getting that log, then category is "Weapon"

rich egret
#

That's why it's weird

polar acorn
#

Have you tried actually logging it to see what value it is

rich egret
rich egret
polar acorn
shadow rain
#

how could i reference clones from an instantiate?

polar acorn
shadow rain
#

alr so i dont need to make one?

polar acorn
#

Make what

shadow rain
#

a reference to it

#

cuz i wanna delete clones from instantiate if a button is presssed

rich adder
#

put them inside a list

polar acorn
#

You don't "make" a reference, you get a reference

rich adder
#
var theObject = Instantiate(etc..
myListOfObjects.Add(theObject);```
polar acorn
#

A reference is just a way to access a different thing

#

Instantiate gives you one

shadow rain
#

hmm ok ty

subtle linden
#

I´m a dumb Unity newbie lol working on a 2d project, I have a character that can jump. The jumping worked fine before.
I changed some settings for the UI scaling and... suddenly it doesn't jump anymore? I know the jumping function is getting called properly and I´ve played with the movement values to no avail, so I think it has to do with the different objects parameters in Unity...? I checked with the version where the jumping did work and nothing is different on the objects or the script I used, so I'm a bit unsure where to look next.
I have a Debug.Log line that shows me I enter the jumping method and the following line is what doesn't seem to take effect, with jumping power as 6f, the same value it was before the UI scaling (have played with this variable to test if the number could be an issue but it didn't make a difference, should I try any different values? calculate it a specific way?)

rb.velocity = new Vector2(rb.velocity.x, jumpingPower);

The character always falls down when I run the game and gets stuck in the middle of the ground collider. Depending on the initial position I set for the character, it sometimes gets moved away from the screen, just off the ground collider and gets stuck there. So I think the issue lies in this initial position change...?

Both the ground and the character have box colliders. None of them work as triggers.

First image is the character rigidbody + collider, second image is the ground's collider. Should I be checking anything else?
(since someone was asking abt another issue before, feel free to make a thread if you reply to me or smthn lmao)

polar acorn
#

Are you using a GetButton instead of a GetButtonDown?

#

It could be adding force for every frame the button is held

thorny orchid
#

If you don't want the player to do that (hold the spacebar) check for getkeydown and not getkey

shadow rain
rancid tinsel
polar acorn
shadow rain
#

do i need to do brackets when putting the var

#

like i named it paint

#

do i need to do paint();

polar acorn
polar acorn
shadow rain
#

paint;

polar acorn
subtle linden
thorny orchid
polar acorn
rancid tinsel
shadow rain
#

thats it

polar acorn
rancid tinsel
shadow rain
rich adder
rancid tinsel
shadow rain
polar acorn
rancid tinsel
#

but it never pauses the game with the bit in enemyspawner, the levelmanager timescale buttons work fine

polar acorn
#

It's just a variable

#

sitting there

#

alone

shadow rain
#

paint is the instantiate

#

rlly

polar acorn
#

like Dr. Manhattan on mars

rich adder
shadow rain
#

no?

rich adder
#

thats why i mentioned storing it in a list if you want to erase a bunch spawned

polar acorn
rancid tinsel
shadow rain
#

!code

eternal falconBOT
rancid tinsel
#

the timescale shouldnt change from when i set it to 0

polar acorn
shadow rain
#
// Your code here
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PenDrawScript : MonoBehaviour
{
    [Header("Keybinds")]
    public KeyCode ClearKey = KeyCode.Backspace;

    public GameObject pen;
    public GameObject effect;

    public bool drawing;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        var paint = Instantiate(effect, pen.transform.position, Quaternion.identity);

        
        if(Input.GetMouseButton(0))Instantiate(effect, pen.transform.position, Quaternion.identity);

        if(Input.GetKey(ClearKey) && pen.tag == "Paint")
        {
            
        }
    }
}

#

script is unfinished***

#

i need to get rid of the bool too**

polar acorn
rancid tinsel
#

like ctrl F but for all scripts at once

rich adder
#

you're literally assigning a newly spawned on to the same variable

shadow rain
#

its in update cuz every frame? no?

polar acorn
shadow rain
#

plus u said to leave the var on its own

rich adder
shadow rain
#

i thought i should put the other instantiate back

shadow rain
rich adder
polar acorn
#

Why is "Jump" an axis

shadow rain
polar acorn
shadow rain
#

or is it just an example?

rancid tinsel
polar acorn
pseudo canyon
#

is multiplayer beginner coding or advanced coding i can't tell

polar acorn
polar acorn
#

You should probably make it a button

thorny orchid
pseudo canyon
polar acorn
rich adder
# shadow rain here

something like this basically

[SerializeField] List<GameObject> paints;
void Update()
{
    if (Input.GetMouseButton(0))
    {
        var paint = Instantiate(effect, pen.transform.position, Quaternion.identity);
        paints.Add(paint);
    }
    if (Input.GetKey(ClearKey))
    {
        for(int i = 0; i < paints.Count; i++)
        {
            Destroy(paints[i]);
        }
        paints.Clear();
    }
}```
pseudo canyon
#

is there a help channel

rancid tinsel
#

yeah works in OnAwake(), thanks for the help

polar acorn
thorny orchid
polar acorn
#

You can still check if a button is held without it being an axis. You can start your jump on GetButtonDown, and adjust the height based on when they release the button

polar acorn
#

Also, isn't "Controlling the height by holding the button" literally the problem you're trying to solve?

#

You said you didn't want that to happen

shadow rain
summer stump
#

GetKeyDown is only true for a single frame

#

You can use GetKeyUp to see when the press is released
Then calculate the difference in time

rich adder
cold fable
#

hi

pseudo canyon
#

i can't tell if multiplayer movement being client sided is a networking issue or a script issue, what do i do?

summer stump
pseudo canyon
#

and movement is client sided

summer stump
#

Yeah I got that part haha 😸

pseudo canyon
#

i don't know if it's movement issue or script issue

#

where do i post for hlep

#

for help

summer stump
#

The "client sided" part is what makes no sense

pseudo canyon
#

client sided = pc that is connecting

#

server sided = server

summer stump
pseudo canyon
#

yes but idk if it's a movement issue or a networking issue

#

so uh

#

yeah

summer stump
subtle linden
pseudo canyon
#

which means only you can see it

#

server can't see it

#

i think

#

or am i dumb

summer stump
#

You have to send the inputs to the server of course

#

But the movement would happen on the client

pseudo canyon
#

i'm confused

#

i don't know how to do that

#

(since i don't use unity alot)

summer stump
# pseudo canyon i'm confused

First. Don't ask in code BEGINNER haha. It is an advanced topic. And you were directed to #archived-networking anyway
But it depends on the networking framework you are using and what architecture you're going for. It's impossible to speak in generalities here

pseudo canyon
#

what do you mean

#

i don't undergrand

polar acorn
pseudo canyon
polar acorn
pseudo canyon
#

i am using multiplayer HLAPI

ruby python
pseudo canyon
polar acorn
pseudo canyon
#

oh

#

wait

#

isn't mutliplayer hlapi deprected

polar acorn
#

Pretty sure

pseudo canyon
#

yeah it is

#

i just

#

checjked

#

is that a bad thing

#

that it's

#

deprected

summer stump
rich adder
shadow rain
#

ok so ik ive used this channel WAAYYYYYY tooo much but this is the LAST thing for today. I added a colour changing script for more colour variants obvs but it changes all paint instead of just the new paint if yk what i mean. Ik what is wrong with the script i just dont know how to fix it. It is bc im refrencing all of the paints insted of new ones

#

!code

eternal falconBOT
shadow rain
#
// Your code here
  using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ColourChangerScript : MonoBehaviour
{
    public SpriteRenderer sprite;

    public bool newPaint;

    // Start is called before the first frame update
    void Start()
    {
        sprite = GetComponent<SpriteRenderer>();
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetMouseButton(0))
        {
            newPaint = true;
        }

        if(Input.GetKeyDown(KeyCode.R) && newPaint == true)
        {
            sprite.color = new Color(1, 0, 0, 1);
        }

        if(Input.GetKeyDown(KeyCode.B)&& newPaint == true)
        {
            sprite.color = new Color(0, 0, 1, 1);
        }

          if(Input.GetKeyDown(KeyCode.G)&& newPaint == true)
        {
            sprite.color = new Color(0, 1, 0, 1);
        }

           if(Input.GetKeyDown(KeyCode.C)&& newPaint == true)
        {
            sprite.color = new Color(0, 0, 0, 1);
        }
    }
}

#

script

polar acorn
wintry quarry
shadow rain
polar acorn
shadow rain
#

I really dont know ive tried searching it up but there isnt anything useful

pseudo canyon
#

how do i lock the cursor to the middle of the screen

shadow rain
#

waait i can help

polar acorn
#

I mean how are you the person making the game, intending to choose which things to color

shadow rain
#

ik ik

shadow rain
#

!code Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;

eternal falconBOT
shadow rain
#
// Your code here
  Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
lost anvil
#

@rich adder damn bro i just had to make pointdistance higher then the stopping distance you were right 😭

#

i spent a good hour trying to fix the script that was right

rich adder
#

the power of Debugging numbers!

lost anvil
#

lol ill be debugging thoroughly from now on

shadow rain
#

actually is there a way of saving the screen. What I mean is that instead of changing the new instantiated objects color I could save the existing ones meaning the only the instantiated objects will change. Is my logic correct?

summer stump
shadow rain
#

alr will do

hushed hinge
shadow rain
#

WAIT NVM

rich adder
shadow rain
#

so yk how u need a var what would that =? thats what i meant.

shadow rain
summer stump
rich adder
rich adder
#

so share the list, doesnt have to be in the same script

shadow rain
#

ok

rich adder
#

do you know how ?

rich adder
#

also doing this inside every keypress Camera mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();

shadow rain
rocky lava
#

anyone know why this doesnt work?

rich adder
rocky lava
#

wrong image

shadow rain
rich adder
rich adder
#

and what are u struggling with

shadow rain
#

u said to share the list

shadow rain
rich adder
#

you want to change to colors to all the things you spawned ?

#

keep it all in one script if it helps you understand better

rocky lava
shadow rain
#

I want to change the colour when a button is pressed but not the ones already on the screen

rich adder
buoyant schooner
rich adder
#

If you are following tutorial its either bad or you missed a step where they created those methods in that Interactable class @rocky lava

rocky lava
#

heres my full code

rich adder
eternal falconBOT
rich adder
#

cause your error wasn't highlighting in editor

#

which is a big problem coding without intellisense/error underline working

rocky lava
#

ah

#

i thought i installed that a few weeks ago

rich adder
#

well it needs to be configured for Unity

#

otherwise is just as good as a text editor

shadow rain
rich adder
# hushed hinge

so your goal has DoorInteraction which calls OnTriggerEnter2D but has no collider?

rocky lava
hushed hinge
hushed hinge
rich adder
#

triggers dont block any object but send trigger messages

hushed hinge
rich adder
#

you just didnt catch the error because it never ran

#

you should store these cameras in the beginning of the Level btw.
not sure why you're doing this

Camera mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
        Camera mainCamera2 = GameObject.FindGameObjectWithTag("MainCamera2").GetComponent<Camera>();
        Camera pixelCamera = GameObject.FindGameObjectWithTag("PixelCamera").GetComponent<Camera>();```
This is a Null Ref Waiting to happen..
shadow rain
#

my game is very good rn

ebon ember
#

How would you assign a integer to a string in a list?

#

if that's possible

#

basically I have a varialbe and I want to assign more than one integer value to it

rich adder
ebon ember
#

can I assign more than one integer to a variable?

shadow rain
#

actually how could i make a designated area for the drawings?

rich adder
ebon ember
rich adder
#

you can make a tuple

ebon ember
rich adder
#

you can also make a struct

#

prob better

#

a class works too ofc

ebon ember
#

alr ima look into that, thank you

hushed hinge
hushed hinge
rich adder
hushed hinge
#

I don't know hot to fix the error

hushed hinge
rich adder
rich adder
#
[SerializeField]
private Camera mainCamera, mainCamera2, pixelCamera;```
#

then remove the = Find, this will guarantee those are assigned

queen adder
#

How do u make animations for ur movement

rich adder
rich adder
hushed hinge
#

I meant when oyu said "remove the = find"

rich adder
tender stag
#

i need to add enough force so the player stays at the water surface

#

without bouncing

rich adder
#

use the newly created variables

queen adder
rich adder
rich adder
queen adder
#

I got all the movements but I don't know how to add Animations for it

rich adder
queen adder
#

Bro _

hushed hinge
rich adder
#

the one in TeleportPlayer too

hushed hinge
rich adder
hushed hinge
#

oh right

queen adder
hushed hinge
rich adder
#

fading background color of camera doesn't make much sense to me

#

your objects will be infront background of camera

#

just switch it out from camera to a UI Image stretched to Screen

#

then fade the alpha

#

you can easily just keep current code and make one color full alpha and other with no alpha

hushed hinge
rich adder
rich adder
#

how visible it is

hushed hinge
rich adder
hushed hinge
hushed hinge
rich adder
#

yea

rich adder
rich adder
#

also send code you write in code snippets like here

hushed hinge
#

code snippets?

rich adder
#

dont send screenshots of code

junior socket
#

!docs

eternal falconBOT
hushed hinge
rich adder
eternal falconBOT
rich adder
hushed hinge
rich adder
#

fadeIn and fadeOut respectively

hushed hinge
# rich adder

even if I wanted to, it just won't sent because of text being too long

hushed hinge
rich adder
hushed hinge
rich adder
#

you can prob get more fancy results using a curve on the float of alpha only or maybe even dotween

hushed hinge
#
public string playerTag = "Player";
    public string interactionButton = "q";
    public string player2Tag = "Player2";
    public string interactionButton2 = ".";
    public AudioClip doorSound;
    public Transform teleportTarget;
    public float fadeDuration = 1f;
    public Color fadeColor = Color.white;
    Color fadeInColor = Color.white;
    Color fadeOutColor = new Color(1, 1, 1, 0);
    [SerializeField]
    Camera mainCamera, mainCamera2, pixelCamera;
rich adder
#

hopefully you're somewhat understanding why you are changing what you're changing..

hushed hinge
#

also should I put fadeInColor and fadeOutColor somwehre?

rich adder
hushed hinge
#

XD

rich adder
#

ok think about your method FadeCameras first

#

which, should probably now be FadeScreen

#

StartCoroutine(FadeToColor(...
what you think goes here

hushed hinge
#

delete some of the line?

rich adder
#

you're literally replacing the two things you changed

#

make the fields for the image components you have

#

plug them in the method and ur done

hushed hinge
tender stag
hushed hinge
#

I'm not good with quizes

rich adder
#

hoping you at least took away some knowledge from this change but 🥲

hushed hinge
rich adder
tender stag
wild fox
#

there is this object with navmesh attached and nodes telling the object where to navigate, on destroying i need to spawn a tank. But when i spawn the tank, they are either stuck at some node on the map of some level or stuck on the ending node on the other scene

rich adder
# tender stag what way

depends how underwater you want it to be, I put a sphere-like check on the players head usually or you can do chest

hushed hinge
rich adder
#

using velcoty random - number , seems to magic

tender stag
#

i wanna do it using physics

#

and forces

rich adder
tender stag
#

thats the problem

sterile wraith
#

How do I ensure that no matter what two gameobjects will be connected at a point. So like in a car, you have 4 tires. obviously the 4 tires are moving and your chassis is going along with it. but how can i ensure that the chasis stays where it is relative to the tires even when the tires are moved.

rich adder
#

wrong

#

thought it was clear background color on camera does Nothing with sprites infront of it..

hushed hinge
#

then what am i supposed to put there?

rich adder
#

your new Coroutine is fading an Image component

hushed hinge
rich adder
#

did you not write any of the code ? you need the do the same thing you did for the camera..

#

writing random syntax like that does nothing

hushed hinge
#

ok, I'm so lost here right now

#

you mean the transition name?

rich adder
#

..all the camera stuff needs to be gone and replaced with Image component , that is all..

#

camera.backgroundColor has no affect being behind sprites..

#

so its a useless fade

hushed hinge
#

oh ok

rich adder
#

make a thread if you want to continue

#

i'll explain better

visual hedge
#

or it's just a split screen game?

rich adder
#

I think its a couch co-op

hushed hinge
#

it is coop

visual hedge
#

oh okay, so split-screen, okay

hushed hinge
#

transition fade screen

#

why? I'm the one who made the thread

rich adder
#

you cannot write too short

#

bot doesn't like that

#

ideally keeping from spamming vertically

wild fox
#

@rich adder can you assist me later pls? once you are done helping him

rich adder
wild fox
wild fox
hushed hinge
#

it's ok

rich adder
#

Also where is the code

wild fox
#

yeah gimme a min

wild fox
#

when i call it on start, it works on few levels that the tank spawns, but on some levels it doesn't work. I can't seem to figure out why

outer light
#

hi

rich adder
#

or better yet on it

#

do a SamplePosition first

wild fox
#

the other code which is responsible to navigate the object on the path, i dont know how to integrate it into my newly spawned object so that the object follows the same path. From what i can understand i need to connect the 2 scripts but i dont know how exactly.

rancid tinsel
#

what might have happened here? it was 2.7 and added 0.1 to it and turned into this

sterile wraith
rancid tinsel
rich adder
eternal needle
rancid tinsel
rich adder
#

lol

sterile wraith
#

they arent.

rich adder
#

use the constraint components then

sterile wraith
rich adder
sterile wraith
#

their position

#

i wasnt using a rigidbody or a cc. literally their position

rich adder
#

are you're saying you are assigning it a value?

#

just use the constraint component then

sterile wraith
sterile wraith
rich adder
#

just so you know AddForce doesn't work while .velocity is running not sure if you knew that

#

also dont see anywhere you're incresing jumpHeight based on Jump input held

#

it probably breaks cause you have soo much going on the script is kind of a mess

finite dew
#

Reduce gravity on player while player is in air and moving up and holding jump

#

That's a good approach I always use

rich adder
#

all you really need is increase a float number by GetKey

finite dew
young wren
#

Hi again i try to make Scriptable Object that store bool value at 2 states initial - "initialValue" and runtime "value"

But i can't figure out how to set value to be same as initialValue at open game (i mean on what even i should call Initialization function?)

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

namespace RPG
{
    [CreateAssetMenu]
    public class BoolValue : ScriptableObject
    {
        [SerializeField] private bool initialValue;
        [NonSerialized] private bool value;

        public bool InitialValue
        {
            get { return initialValue; }
        }

        public bool Value
        {
            get { return value; }
            set
            {
                if(this.value != value)
                {
                    this.value = value;
                    OnValueChanged?.Invoke(value);
                }
            }
        }

        private void Initialization()
        {
            Value = InitialValue;
            Debug.LogWarning("Change BoolValue to: " + InitialValue);
        }

        private event Action<bool> OnValueChanged;

        public void ToggleValue()
        {
            Value = ! Value;
            Debug.Log("BoolValue toogle");
        }

        public void SetValueByObjectState(GameObject targetObject)
        {
            Value = targetObject.activeInHierarchy;
            Debug.Log("Set BoolValue by hierarchy to: " + targetObject.activeInHierarchy);
        }

        public void SubscribeToValueChanged(Action<bool> callback)
        {
            OnValueChanged += callback;
        }

        public void UnsubscribeFromValueChanged(Action<bool> callback)
        {
            OnValueChanged -= callback;
        }
    }
}
visual hedge
#
        {
            Value = InitialValue;
            Debug.LogWarning("Change BoolValue to: " + InitialValue);
        }

I might be dumb, but won't

        {
            Value = InitialValue;
            Debug.LogWarning("Change BoolValue to: " + InitialValue);
        }
``` be what you want?
#

or void Start(){Initialization();}

finite dew
whole isle
#

how do i start my unity game but in full screen

young wren
visual hedge
whole isle
#

ty

young wren
finite dew
#

Custom inspector I mean

young wren
#

Yeah sure i thought too about some kind of "bootloader" or smth but i belive theres a better solution then manually put every scriptable object like this to script that gona call function on each of them

finite dew
young wren
#

I think its about "GetKeyUp" it only works when u release key as function name says Get Key Up 😛

finite dew
#

Instead of calling jump with the time held, consider calling it immediately, and reducing the gravity of the rigidbody. Restore it when spacebar is not held

fathom gate
#

I’m trying to use the virtual scripting, but for some reason my all of my nodes aren’t in my script graph and I can’t find them

finite dew
fathom gate
finite dew
#

you never set isJumping to false, which means the gravity is now forever changed

#

you need to set it to false when your jump button is not pressed

#

you're adding half of a reverse gravity artifically upwards, when holding jump. You are turning off normal gravity when grabbing a ledge
but when you're grabbing a ledge and holding jump, the half of reverse artifical gravity is still applied

tender breach
finite dew
#

in the rigidbody2D settings

#

gravity scale should be zero

#

if you're moving it from within the script

tender breach
#

That was the issue, thanks

finite dew
#

maybe
if (isJumping && myRB.useGravity)
{
myRB.AddForce(Physics.gravity * (jumpGravityMultiplier - 1), ForceMode.Acceleration);
}
?

#

sadly, I don't know enough about your project to help, but maybe there is a good solution along that path

#

anyway I'm going to sleep now

young wren
#

Any idea why my script to change image of button on start would not work?

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

namespace RPG
{
    public class ImageByBoolValue : MonoBehaviour
    {
        [SerializeField] private BoolValue objActiveValue;

        [SerializeField] private Image image;
        [SerializeField] private Sprite trueSprite;
        [SerializeField] private Sprite falseSprite;

        private void Start()
        {
            setImageSpriteByValue(objActiveValue.Value);
        }

        private void setImageSpriteByValue(bool value)
        {
            if(image != null)
            {
                Debug.Log("Obj image set : " + this.gameObject.name + " -> " + value);
                image.sprite = (value) ? trueSprite : falseSprite;
            }
        }
    }
}

All properties are setted and it returns true so i expect to it change image from falseSprite to trueSprite but it doesn't on Start

(later if i change flag manually or by click for example it works)

#

OnRenderImage?

#

nah same effect 😦

young wren
#

Nope

ivory bobcat
#

Are you receiving any logs?

young wren
#

On start its same as falseSprite

ivory bobcat
#

Define "work"?

young wren
ivory bobcat
#

Show what it logged.

#

It'd only change from false sprite to true sprite if it were false to begin with and if the value was true.

young wren
#

Debug.Log("Image : " + image);

            Debug.Log("image.sprite.name: " + image.sprite.name);

            Debug.Log("falseSprite : " + falseSprite.name);

            Debug.Log("trueSprite : " + trueSprite.name);

            Debug.Log("flag : " + value);

            Debug.Log("GameObject : " + this.gameObject.name);
#

ohh my bad flag somehow is false?

ivory bobcat
#

What didcs Debug.Log("Obj image set : " + this.gameObject.name + " -> " + value);logged?

young wren
#

Wait wrong object on screen

#

I changed this Debug.Log u wrote to this above with more informations

#

All looks fine but image ain't changing when it's called from Start function

ivory bobcat
fathom gate
#

how to i set or find a working variable?

rich adder
#

strings are much caseSensitive

fathom gate
young wren
#

@ivory bobcat i don't think it is i added Debug.Log after changeing it and it have still wrong sprite like it didn't evevn change value under image.sprite

rich adder
#

I dont even see you defining it

ivory bobcat
fathom gate
young wren
#
        private void setImageSpriteByValue(bool value)
        {
            if(image != null)
            {
                Debug.Log("Image : " + image);

                Debug.Log("image.sprite.name: " + image.sprite.name);

                Debug.Log("falseSprite : " + falseSprite.name);

                Debug.Log("trueSprite : " + trueSprite.name);

                Debug.Log("flag : " + value);

                Debug.Log("GameObject : " + this.gameObject.name);

                image.sprite = (value) ? trueSprite : falseSprite;

                Debug.Log("image.sprite.name after chang: " + image.sprite.name);
            }
        }

And last debug returns name of sprite that was before change

rich adder
#

I guess somewhere in the graph , no clue about visual scripting

ivory bobcat
#

Verify the inspector values and that it's the expected object

young wren
#

In inspector it also shows wrong value

#

Im quiet sure it's somehow about event life cycle but idk how fight it

#

Cause when i use this function from an button it works perfectly 😐

ivory bobcat
# young wren

It looks correct. The flag was false so your result would be the false sprite.

#

Which was layerbase

young wren
#

Wrong console.log didnt clear console xd

minor patio
#

can we talk about IEnumerables? I have a list of type Competency that is returning null on my calls to it in other methods... 😦
The strange thing is I've got a display area in my UI that is displaying the various Competency titles and is a parent object to an Improve button that I'm using to increase the rank of a competency. I've either got my lambda's incorrect where I'm using them, or the IEnumerable class needs work, or both.

ivory bobcat
# young wren

So the flag was true and you got the true sprite layersactive. What's the issue?

young wren
#

i got falseSprite

silk night
young wren
ivory bobcat
young wren
#

yeah but Image component dont get that

#

its still LayersBase

ivory bobcat
silk night
minor patio
ivory bobcat
#

For instance, your image reference may not be the expected image cs Debug.Log($"Click me to see the image we're changing", image); @young wren

silk night
#

When you are calling the list in your function, are you sure the list is null and not the class? like this part -> holder.list

silk night
minor patio
silk night
#

!code

eternal falconBOT
minor patio
#

I know there's some code missing from the display script (I haven't implemented the display of a competency's rank)...

#

it might also have something to do with the fact that I'm not Updating my displays

silk night
#

And what part is returning null?

#

also a note, your singleton thing in the awake would destroy the singleton if you instantiate a second one by fault, did you mean to do Destroy(gameObject) there? If you get a second one you are left with none afterwards, or rather a reference to a destroyed gameobject

minor patio
#

which Awake? 😛

silk night
#

Competencies awake

minor patio
#

I'm an IEnumerable virgin X)

young wren
silk night
minor patio
silk night
gloomy jacinth
#

Can someone help me? I need my hands to collide with objects and not phase through. Its for unity vr

minor patio
silk night
silk night
minor patio
#

line 163 in the dump

silk night
#

ahh

silk night
gloomy jacinth
#

Let me check

#

Where do i check that?

silk night
silk night
gloomy jacinth
#

Oh, no it is not marked static.

silk night
#

do you want your hands be blocked by the wall or do you want your wall to move when you hit it?

gloomy jacinth
#

so my door does work i dont know if its becuase my hands phase through it so it doesnt open or its bad colliders.

#

with either one

silk night
#

so you want to move the wall/door with your hands?

minor patio
gloomy jacinth
silk night
gloomy jacinth
#

i can send a video if you want to see the situation?

silk night
silk night
#

its a static, so it should be available once you have spawned one instance of Competencies and the awake has fired

minor patio
gloomy jacinth
#

Dont mind the wisphering and stuff

#

It can open slowly with two hands but i want to hit it with one hand and it opens like wide enough and smoothly

silk night
#

Do you have colliders on your hands?

#

im not 100% sure about the vr controls

gloomy jacinth
#

i have sphere colliders but i dont think their doing much because they dont seem to be colliding correctley

#

do u know the settings i need for that?

silk night
#

to me it looks like the only thing that can interact with it is the flashlight

gloomy jacinth
#

Ya probably, I dont know how to do that with the hands tho becuause i can put in the same colliders and it wont do anything

silk night
#

as i said not fully sure about how the hands are handled in unity, never worked with it but i can imagine that the collision resolving does not work fully cause of the "unusual" nature of those colliders, moving directly by 3d input

gloomy jacinth
#

The flashlight has a small capsule collider but thats it

silk night
#

can you disable the flashlight and see if you can move the door at all?

gloomy jacinth
#

lemme test it

silk night
gloomy jacinth
#

@silk night i can still collide with it but it still sucks

silk night
#

can you show me the settings of your door rigidbody?

gloomy jacinth
#

yes

silk night
gloomy jacinth
rancid tinsel
silk night
#

At this point i would assume its directly related to VR, and at that point i cannot help anymore, I suggest the links i sent above and #🥽┃virtual-reality if you need further help

silk night
#

oh you posted code, let me check that

silk night
minor patio
# silk night Try using `Competencies.CompetenciesInstance` instead

I get a null reference at line
''var competency = Competencies.CompetenciesInstance._competencies
.Where(comp => comp.competencyTitle == competencyTitle.ToString())
.FirstOrDefault();''
now. Pretty sure it's the _competencies which is the culprit... but I've tried a couple of different edits on the lambda & no dice

rancid tinsel
silk night
rancid tinsel
minor patio
#

sorry about the patch formatting

rancid tinsel
#

this is the settings script

minor patio
silk night
tough trench
#

Anyone know how I can add a multiplier to the money

silk night
rancid tinsel
#

yeah that fixed it thank you 😭

silk night
minor patio
tough trench
silk night
#

i mean yeah it does the same, but ive never seen it done manually 😄

minor patio
silk night
#

a list is a child of IEnumerable

#

it exposes the same functionality

minor patio
silk night
minor patio
silk night
#

i mean where are you using it right now 😄

#

so at first you should add

_competencies = CompetenciesList()

to the Awake

Next replace CompetenciesList() in line 27 with competencies so you used the cached value

minor patio
#

var competency = Competencies.CompetenciesInstance._competencies
.Where(comp => comp.competencyTitle == competencyTitle.ToString())
.FirstOrDefault();
here again? just maybe formatted differently?

shell sorrel
#

that is a lot of stutter in 1 line

silk night
#

oh yeah that lambda usage has nothing to do with it being a list directly

#

its just a syntax for anonymous functions

#

also use
```cs
CODE
```

#

to post code here

granite atlas
shell sorrel
#

also you can ditch the .Where and just toss the lambda in FirstOrDefault

minor patio
#

oh, it's three ''' now

silk night
#

its backticks

#

and if you add cs in the first line it even does c# highlighting

shell sorrel
#
var competency = Competencies.CompetenciesInstance._competencies
    .FirstOrDefault(comp => comp.competencyTitle == competencyTitle.ToString());

for example

tough trench
#

nvm got it

silk night
# minor patio oh, it's three ''' now

I see you are having trouble with lambdas, to make you understand it easier ill give you an example of what they are, you will understand easier 😄

shell sorrel
#

also would try and reduce the stuter a little like no need to call the intance CompetenciesInstance

#

just instance would be good enough

minor patio
shell sorrel
#

also these linq stuff and lambdas you can just 100% ignore if you want

#

its really just shorthand for stuff you can do with a loop

minor patio
summer stump
royal linden
#

can someone help i am using a script from yt and i can only look up and the camera doesnt follow the player

eternal falconBOT
silk night
# minor patio cheers - it's grade 4 average for me
class Test {
    public void Testing(string value) {
      Debug.Log(value)
    }
    
    public void Main() {
      var list = new List() //Imagine this is a filled list
      list.ForEach(value => Debug.Log(value))
      list.ForEach(Testing)
    }
}

Both calls to foreach do the same here, one is a named function, the other one is anonymous, the things before the => are the arguments, behind it is the executed code (mutliple arguments can be done like (value1, value2) => code)

shell sorrel
minor patio
shell sorrel
royal linden
grizzled zealot
#

Is it normal to have tons of scripts layered onto game objects? I moved to the MVC pattern and now have 14 scripts layered onto a single item: moving, shooting, health, selectable, localGUI, grouping, faction. There's no end in sight.

shell sorrel
silk night
shell sorrel
#

though feels odd you would have GUI stuff on the same object

#

like moving shooting health etc makes sense UI not so much

grizzled zealot
#

It's local object management (spite colouring, etc)

#

I shouldn't call lit UI.

shell sorrel
#

ah

grizzled zealot
#

It's all the stuff the other views don't directly manage.

summer stump
royal linden
summer stump
summer stump
#

I aint downloading anything

silk night
# royal linden
  1. Your script only modifies the rotation of the playerCamera
  2. Your script only modifies the x axis of the rotation of your camera, so you can only look up and down
silk night
summer stump
#

Which is why sending it like that is against the rules on this server

grizzled zealot
summer stump
#

But if someone can and is willing to help, it's all good

summer stump
#

Components are simply data containers, which can also hold visual or input data

silk night
summer stump
#

Entities are basically just indexes

royal linden
summer stump
#

Systems are logic
Components are data
Entities are indexes for the components being acted ok by the systems (and form archetypes inside chunks)

grizzled zealot
#

The SOs+live stats object form the model.

summer stump
silk night
minor patio
silk night
silk night
dark kettle
thorn holly
dark kettle
#

I dont want the buildings to move, I want more to spawn. I want an endless amount of buildings for the player to swing to/from

rich adder
#

how do you want to spawn them, where in relation to player, etc..

#

using a trigger probably wont scale well

dark kettle
#

I thought my code handled that tbh. 0-51 of whatever measurement that is away from the building that the trigger box was entered/exited of

rich adder
#

you're putting world coordinates

dark kettle
#

those are world coordinates?

#

how do I make it local, then?

rich adder
#

yes you would need to use +

dark kettle
#

+?

#

ohhhh

#

wait no I dont get it

rich adder
#

Vector3 thePosition = theBuilding.transform.position + new Vector3(etc.

dark kettle
#

I thought I did lol

#

so how would I modify this code to do that?

 if (other.gameObject.CompareTag("New_Building_Trigger"))
        {
            Instantiate(Building, new Vector3(Random.Range(0,51),0, Random.Range(0,51)), Quaternion.identity);
        }```
rich adder
#

if you want it to relation of the building that spawned new building

minor patio
rich adder
#

also Random.insideUnitSphere is also an option

dark kettle
#

hows that different from the random.range?

#

so for your first suggestion, it would be:

 if (other.gameObject.CompareTag("New_Building_Trigger"))
        {
            Instantiate(Building,Vector3 thePosition = theBuilding.transform.position + new Vector3(Random.Range(0,51),0, Random.Range(0,51)), Quaternion.identity);
        }

???

and what is thePosition and theBuilding?

rich adder
#

try to understand what is happening

#

Vector3 thePosition is a made up example name, and it certainly would not be declared inside a method param like that

dark kettle
#

I dont understand what is happening or how to apply what you mentioned

rich adder
#

start with c#

#

learn how to store info in variables etc

dark kettle
#

I know what variables do, but I dont get how to apply what you mentioned to my situation or what that difference does

bronze trout
rich adder
summer stump
dark kettle
#

I tried to apply what you mentioned to my code though, and I wanna make sure I applied it correctly. I dont have a variable for the position or the building, though, so the variables dont make sense in the current context

bronze trout
rich adder
dark kettle
#

I missed that

#

so would it look like this?

        {
            Instantiate(Building, transform.position + new Vector3(Random.Range(0,51),0, Random.Range(0,51)), Quaternion.identity);
        }
dark kettle
#

it still doesnt work

rich adder
dark kettle
#

how can I do that? I know how to do that in unreal, but not here

rich adder
#

Debug.Log($"hit {other.gameObject.name} tagged with : {other.gameObject.tag}");

teal viper
silk night
teal viper
#

I do it often too. Specifically when I want to diagnose a system as a whole and not fix one specific bug.

dark kettle
#

no debug about what I put in the script, but there is this thing from a plugin that the file came with on install

teal viper
dark kettle
#

I remember debug.log now, its been a while since I had to type that. yea, I only ever use that loll, its pretty effective

silk night
dark kettle
#

how so?

#

that has to do with the swing mechanics, not the building system

long oracle
#

Hey i got a question on a bug and its most likely user error

#

i got bones and animation but how do i assign that to each other

#

everything ive done has failed and im stuck t posing lol

teal viper
#

Is that code related?

long oracle
#

my bad

#

im in the wrong section i think

dark kettle
#

im annoyed that idk how to fix my procedural building spawner

teal viper
#

And go learn the basics.

dark kettle
#

that doesnt really help me with this problem specifically. its definitely important to learn, although I thought I had learned them, but thats not really practical advice for this particular coding problem. also, I am used to unreal blueprints, and its been a while since Ive messed with code, so I am familiar with programming enough to know the basics, just not really able to figure out this problem here. Im trying to get back into unity, but it annoys me that I can run circles around myself in unreal compared to here

radiant frigate
dark kettle
#

a crypto miner that lets you download ram

radiant frigate
#

fr

thorn holly
#

And you might even figure it out yourself