#💻┃code-beginner

1 messages · Page 18 of 1

bright violet
#

yes

#

on the right they have a number don't they

shadow flame
languid spire
#

no, look to the right

bright violet
shadow flame
rich adder
#

you don't want to hardcode scene numbers

shadow flame
#

i dont under stand how to do it

rich adder
#

did you read link what I sent ?

calm coral
shadow flame
rich adder
shadow flame
#

😦

rich adder
#

you have to understand that you have access to that list through buildIndex property

shadow flame
#

some thing like get active scene + 1

rich adder
#

sure stuff like that

polar acorn
rich adder
#

yup. its literally in the link as example code

shadow flame
#

scene = SceneManager.GetActiveScene();

#

this?

rich adder
#

that gives you the Scene

#

then you have access to other proprieties

#

like index , name etc.

shadow flame
#

i am so confused lmoa

rich adder
#

its literally in english

polar acorn
rich adder
#

if you don't understand the string you might need to do some basic c# courses

shadow flame
verbal dome
#

Get the current scene's build index and add to that. Then load the scene with that number

polar acorn
rich adder
#

whats a proprety

tender stag
#

the input and output slots on the right are slots which are on a different canvas

#

thats why OnBeginDrag is not being called

shadow flame
#

why does this not work

rich adder
#

even tho it works (without using an accessor)

calm coral
rich adder
#

its rare but they have been useful

calm coral
rich adder
#

like doing something once etc

shadow flame
#

how can i send code here

rich adder
eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

rich adder
#

its backticks @shadow flame

shadow flame
#

can some1 fix this 🙏

tender stag
# tender stag

i have slots on a different canvas, and when i try to drag (OnBeginDrag) its not detecting them because there on a different canvas than this script is on and inventory slots are in, how do i go around it?

rich adder
#

but it should not be a function

#

also nice chat GPT code

shadow flame
#

Ik

#

i tried it and it didnt work

rich adder
#

obv its not teaching you fundamnetals of c#.. this will be more of a struggle

rich adder
#

and arent calling LoadNext();

#

you have to remove the function inside a function

#

if statement isn't a function

tender stag
#

and then actually call the function

crude prawn
calm coral
shadow flame
summer stump
#

Now just CALL the function

rich adder
summer stump
#

LoadNext()
Where you want to do it

tender stag
#

i remember these struggles

#

lmao

shadow flame
rich adder
rich adder
calm coral
shadow flame
rich adder
#

at least 1 rigidbody

summer stump
# shadow flame

Sorry to add on, but your nextSceneIndex at the top has nothing to do with the one in the LoadNext function. Whenever you write the type (int in this case) you are declaring a variable. It is a new and unrelated one.

It doesn't matter here, but this misconception may cause you confusion later

rich adder
#

local variable will not affect something with the same name

tender stag
rich adder
#

they're different as far computer knows

rich adder
tender stag
#

and then this is like a military crate

#

it has its own canvas

#

thats why OnBeginDrag is not called

rich adder
tender stag
#

maybe theres like a setting in project settings for the OnBeginDrag to work on all canvases?

#

or like in the event system

rich adder
#

You shouldn't make OnDrag be part of some type of Inventory manager

tender stag
#

why not?

rich adder
#

I wouldn't do it that way

#

because its already doing way too much in 1 script

#

your mixing inventory logic with UI movement /drag logic

tender stag
#

i see what you mean

#

alright i'll put that in the cell script

#

but still

#

the OnBeginDrag is not detecting other canvases

rich adder
#

also other canvases should have the same component obv

#

Graphic Raycaster etc.

tender stag
abstract pelican
#

using System;
using UnityEngine;
using UnityEngine.EventSystems;

public class InputManager : MonoBehaviour
{
    [SerializeField] private Camera sceneCamera;
    [SerializeField] private LayerMask placementLayerMask;

    public event Action OnClicked, OnExit;
    
    private Vector3 lastPosition;
    
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
            OnClicked?.Invoke();
        if (Input.GetKeyDown(KeyCode.Escape))
            OnExit?.Invoke();
    }

    public static bool IsPointerOverUI() => EventSystem.current.IsPointerOverGameObject();

    public Vector3 GetSelectedPosition()
    {
        Vector3 mousePosition = Input.mousePosition;
        mousePosition.z = sceneCamera.nearClipPlane;
        Ray ray = sceneCamera.ScreenPointToRay(mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hit, 100, placementLayerMask))
        {
            lastPosition = hit.point;
        }

        return lastPosition;
    }
}

if I don't build it, everything is displayed exactly, although this was not the case on a regular camera?

rich adder
#

no the canvases

tender stag
#

yeah

#

should the canvases have inventory manager?

#

each one

#

i think that would work

rich adder
#

each one should be smaller managers of their own inventory/stack at very least

#

then communicate that to a bigger manager of stacks

#

think of it like if you disable something it should not break everything else

#

each part should be able to function independently without breaking

tender stag
#

should i put the OnBeginDrag on my slot? and then communicate with my Inventory Manager?

#

that'd be the best option

#

i think

rich adder
#

I usually put it on the individual UI elements

#

all the IBeginDragHandler etc

violet topaz
#

Where should I start more multiplayer matchmaking? i followed Code Monkeys video on Game server hosting(multiplay) and matchmaker but i don't know how to set up the code

rich adder
#

you will just encounter pain

violet topaz
#

This isnt my starter project i just want to make a prototype for a different game that i have been work on for a little

rich adder
#

but i don't know how to set up the code

#

sounds like this is one of your starter project

#

besides specific API stuff to Netcode everything else is normal coding you do in single player

polar acorn
#

If you feel the need to post the question in #💻┃code-beginner you should probably not be touching multiplayer with a ten-foot pole

smoky echo
#

Anyone know why my character like levitates when i attack sometimes? At end is a good example, happens sometimes when im just like on a weird surface also and just attacking, im guessing its my collision box but just wanna check

#

2x speed btw xD

analog lark
#

is there a tutorial or anything

#

on how to make a 2d kinematic rigidbody (with movement, jumping, etc.)

tender stag
#

what is my best option

tender stag
#

could i do this?

#

just have the OnBeginDrag OnDrag etc on the slot

#

and then communicate with Inventory Manager?

#

it looks messy

rich adder
tender stag
#

what do you mean events

rich adder
#

having a giant monolith of different systems is th messy one

tender stag
#

how do i do it cleaner

#

can you help me

rich adder
#

I'm trying mate Inventories vary in complexities, I'm not even sure what you're going for exaclly

#

what is even the purpose of these cells

tender stag
#

just drag and drop to work across different canvases

tender stag
#

there slots

rich adder
#

I get that but why all the drag and stuff from the cell itself

tender stag
#

because when i do it inside Inventory Manager, it doesnt detect the slots

#

because there on different canvases

#

each like chest has its own canvas with slots

#

so when i had OnBeginDrag in inventory manager it only worked for the slots in the inventory

#

(slots attached to the canvas the inventory manager is on)

rich adder
#

I get that but what are you struggling with

tender stag
#

because i wanted to do it that way

#

handle everything inside Inventory Manager

#

but i dont know how

rich adder
#

each slot has their own logic yes?

tender stag
#

this is the slot

rich adder
#

eg, if you drop items into it, should it stack

tender stag
#

no i handle that in OnEndDrag

#

all the logic is here

rich adder
#

wouldnt OnEndDrag go on the actual UI element?

#

like the item itself

tender stag
#

doesnt need to

#

shouldnt at least

#

i really want to handle the OnBeginDrag OnDrag and OnEndDrag in my inventory manager

#

but again OnBeginDrag wouldnt work this way

#

unless you can somehow in project settings make it so that it works on every ui element in the scene

tender stag
#

i have this

rich adder
#

🤷 I wouldn't know, My UI knoweldge only goes as far as card games

tender stag
# tender stag

when i drop items it checks if there is a slot under your mouse

ashen ferry
#

bro has messed up architecture he can keep pushing forward but a lot of his problems stem from the fact responsibilities are all over the place tbh

tender stag
#

then what do i do

rich adder
#

to see whats been dropped into it

tender stag
#

then i wouldnt need the GetCellUnderMouse method?

rich adder
#

I'm not saying thats how you should do it, just saying most of my logic is handled by the Slot class itself

#

since it deals with slot processing the item

#

maybe look at different inventory tutorials, see where they did something you can improve , make better version of combined knowledge

tender stag
#

i already spent last 2 months working on the inventory

#

watched like all the tutorials

#

theres nothing left

rich adder
ashen ferry
#

then u accumulated a lot of lessons to go bald and redo it the sooner the better imo

tender stag
#

did that 3 times

ashen ferry
#

well idk im on 3rd time too now with couple of main systems in my game and its getting cleaner every time lol

#

I bet some of mfs are the 10x devs and can do it right at first try but redoing it is like my main way to do things cause I see why current code sucks at the end

rich adder
#

inventories are def the top furstrating / complex to work on imo

ashen ferry
#

yea

tender stag
#

alright im doing all my drag and drop logic inside the slot

rich adder
#

OnBeginDrag /OnDrop probably

tender stag
#

and end

rich adder
#

why would you end drag a slot?

#

I have EndDrag on my card if its dropped somewhere besides a slot

#

it returns back to original slot/pos

solar heron
#

Hey, how do I get the components parent name?

polar acorn
rich adder
solar heron
tender stag
#

is a click drag and drop easier than actual dragging?

rich adder
#

eh probably a question for UI/UX

ashen ferry
#

prolly same just u start and end it diffrently

analog lark
#

is there a tutorial or anything
on how to make a 2d kinematic rigidbody (with movement, jumping, etc.)

analog lark
#

do you have any particular one in mind

acoustic arch
#

so im attempting to make a gun stay on the screen but itll rotate with the player yet it wont like move from its current position if i look right/left it might change to be like in the middle of the screen

rich adder
acoustic arch
#

like your new pfp btw

rich adder
acoustic arch
#

its on the player, but it acts the same for both of them

analog lark
rich adder
#

oh my

#

please don't do this

#

transform.rotation = new Quaternion(cam.transform.rotation.x, cam.transform.rotation.y, transform.rotation.z, transform.rotation.w);

#

use euler angles

acoustic arch
#

alright

#

i had it originally that

rich adder
acoustic arch
#

oh that was just a test to see how the gun would react

rich adder
acoustic arch
#

k

acoustic arch
#

the cubes just have a mesh filter + renderer

rich adder
# acoustic arch

did u try comment this out activeGun.transform.position = transform.position + gunOffset;

#

oh wait

#

camera holder is not in the player?

acoustic arch
#

oh damn

#

its working now

acoustic arch
#

transform.Translate(transform.forward * speed * verticalInput * Time.deltaTime); is it transform.forward to go up in the x or Vector3.forward?

rich adder
#

forward is blue = z

#

red is .right

#

Vector3 is in worldspace

#

I wouldnt use translate if you plan on using collisions

acoustic arch
#

oh

#

what do i use instead

#

change the position?

rich adder
#

Character Controller

#

or Rigidbody

acoustic arch
#

addforce to it

rich adder
#

if you want physics

acoustic arch
#

its a very very simple game

rich adder
#

CC would suffice if you don't want gravity or physics reactions

acoustic arch
#

alright

rich adder
#

just collisions

#

.Move()

acoustic arch
#

idk how they work really

#

ive done it once ever

rich adder
#

you just switch Translate for Move (ofc from CC component)

#

and its pretty much done

acoustic arch
#

and add the component

rich adder
#

ye

#

[SerializeField] private CharacterController controller;
controller.Move(etc.

acoustic arch
#

alright

violet topaz
#

when use on on click in a button i can cant select a function whats happening?```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SelectClass1 : MonoBehaviour
{
public int whatClass = 0;
public void ARClass()
{
whatClass = 1;
}

}```

acoustic arch
rich adder
acoustic arch
#

it is completely stationary

rich adder
#

show current code

acoustic arch
#

so it currently only goes in 1 direction

acoustic arch
# rich adder show current code

` void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
verticalInput = Input.GetAxis("Vertical");

    characterController.Move(Vector3.right * speed * horizontalInput * Time.deltaTime);
    characterController.Move(Vector3.forward * speed * verticalInput * Time.deltaTime);


    transform.eulerAngles = new Vector3(transform.rotation.x, cam.transform.rotation.y, transform.rotation.z);
}`
#

the movement works just not where im facing

rich adder
acoustic arch
rich adder
#

I would use transform.Rotate(Vector3.up * rotVel);

acoustic arch
#

im not sure what im doing right now

acoustic arch
rich adder
#

transform.rotation = Quaternion.Euler(0, cam.localRotation.y, 0);

acoustic arch
#

oh

#

nvm

acoustic arch
rich adder
#

sure, its just an example

acoustic arch
#

alright so

#

my player still doesnt go in the direction im looking

#

oh wait

#

weird

#

the player rotates like extremely slow

#

when the camera rotates around 360 degrees the player only moves 1 degree

quaint turtle
#

hey guys how are you

#

@everyone

#

@everyone

rich adder
rich adder
quaint turtle
#

thanks

rich adder
#

you knew you was gonna catch a ban

quaint turtle
#

it was my sister

#

souwy

slender nymph
rich adder
acoustic arch
#

the player rotates from 0-1 when the camera goes 0-360 total

rich adder
acoustic arch
#

i would think so, otherwise it shouldnt move at all

rich adder
acoustic arch
#

yeah ill try some stuff, should i remove the players rb

#

cause it has the character controller on it anyway

rich adder
#

why do u have a rigidbody

acoustic arch
#

it does nothing

#

i removed it

rich adder
#

not sure why u added it, anyway does it work without it?

acoustic arch
#

player rotation still is the same as b4 tho

#

should the camera it uses not be a child object of the camera holder?

rich adder
#

because ur rotating the parent I think

acoustic arch
#

alright

rich adder
#

ideally if you were referencing camera holder it wouldn't be an issue prob

acoustic arch
acoustic arch
#

should i send the whole code again?

rich adder
acoustic arch
#

alright

rich adder
#

I did not adhere to my own advice catcrymic

acoustic arch
#

can you explain this afterword btw

rich adder
#

used the quaternion instead of euler

acoustic arch
#

what does euler mean

#

how does it differ from a quaternion

#

(i'm trying to learn)

rich adder
acoustic arch
#

oh interesting

#

which is which

rich adder
#

euler uses degrees

acoustic arch
#

oh so

#

the inspector uses euler

rich adder
#

its showing you euler angles yes

#

if you hit inspector debug mode you can see quaternion values iirc

slender nymph
#

!code 👇

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

acoustic arch
abstract pelican
slender nymph
#

if you want to toggle crouching rather than holding it then instead of subscribing to the canceled event for the Crouch action and checking the current state of the button in onCrouch, you'd want to just flip a bool each time the button is pressed

timid quartz
#

hi all, whenever I close my game I get 1000s of copies of this error and I have no idea where to find out what serialized anything has been "disposed" of
NullReferenceException: SerializedObject of SerializedProperty has been Disposed. UnityEditor.SerializedProperty.get_objectReferenceInstanceIDValue () (at <fe7039efe678478d9c83e73bc6a6566d>:0) UnityEditor.EditorGUIUtility.ObjectContent (UnityEngine.Object obj, System.Type type, UnityEditor.SerializedProperty property, UnityEditor.EditorGUI+ObjectFieldValidator validator) (at <fe7039efe678478d9c83e73bc6a6566d>:0) UnityEditor.UIElements.ObjectField+ObjectFieldDisplay.Update () (at <fe7039efe678478d9c83e73bc6a6566d>:0) UnityEditor.UIElements.ObjectField.UpdateDisplay () (at <fe7039efe678478d9c83e73bc6a6566d>:0) UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <79c7b132c51745cbae03eebea8111c0e>:0) UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <79c7b132c51745cbae03eebea8111c0e>:0) UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <79c7b132c51745cbae03eebea8111c0e>:0) UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <79c7b132c51745cbae03eebea8111c0e>:0) UnityEditor.RetainedMode.UpdateSchedulers () (at <c91a25f185b743118a39aafa100dff09>:0)

timid quartz
#

what does a Layout mean in this context?

slender nymph
rich adder
#

your error seems to be related to something with Unity Editor UI
maybe window or something not disposed properly

abstract pelican
slender nymph
#

where to look for what?

abstract pelican
#

Where to look, I'm just new to this topic

summer stump
abstract pelican
#

I still don't understand why the squat animation doesn't work for me right away, but only in motion

timid quartz
#

that seems to have done it for now, thank you!

#

if I rerun the game and it explodes again I'll come back

rich adder
#

lets see

violet topaz
#

im trying to make a character select screen but i cant the get player to spawn```cs
public class SelectClass1 : MonoBehaviour
{

public int whatClass = 0;
public bool pickedAR = false;

public void ARClass()
{
    whatClass = 1;
}
private void Update()
{
    if(whatClass == 1)
    {
        pickedAR = true;
    }
}

} cs
public class ChangeClass : MonoBehaviour
{
public SelectClass1 Class;
public GameObject ClassSelected;
// Start is called before the first frame update
void Awake()
{
Class = GetComponent<SelectClass1>();

}

// Update is called once per frame
void Update()
{
    if(Class.pickedAR == true)
    {
        ClassSelected.SetActive(true);
    }
}

}```

slender nymph
timid quartz
#

ok yep it blew up.... I think the problem is that I have data that has been serialized and then I'm dumping it when the game stops. like a list of serialized things. and then when I close it, we dump them out of memory but Unity wants to hold onto that data

rich adder
#

could be 2022 bug

timid quartz
#

2022.3.10f1 which I believe is the current LTS?

slender nymph
rich adder
abstract pelican
timid quartz
#

I am going to just un-serialize stuff. I had it serialized so I could sneak some peeks into my data at runtime. but if it that just actually explodes then that's not worth it.

rich adder
#

I just restart editor and fixes it sometimes

#

you could always try deleting library folder and rebuild

#

maybe some nasty bad cache lurking

slender nymph
timid quartz
#

yep, un-serializing my newest thing fixed it.

rich adder
#

weird

abstract pelican
timid quartz
#

my guess is this is what happens when you throw around "system.serializable" as a "show me this in the inspector" and ignoring the fact that setting something up with serialization has genuine memory ramifications, I dunno

#

chalking this one up to something I just had to learn the hard way and moving on, thanks so much!

rich adder
#

idk I never had issues with Serializable

#

def try maybe making unity package with the same assets and use something like 2021 as test

slate badge
#

this might sound dumb but can anyone help me with this?

rich adder
slate badge
violet topaz
#

change class

abstract pelican
#

help guys

abstract pelican
#

maybe there is something to choose?

rich adder
slate badge
rich adder
slate badge
rich adder
#

where did you tell it to shift to that vector

slate badge
violet topaz
#

@rich adder this it the error

rich adder
autumn cargo
#

so the distanceJoint is totally fine

it spawns at the hit.point

however.. the line renderer set to the same position with the raycast hit does not.

it spawns ontop of the game object.

it looks like this (see image)

as you can see the distance joint connects (by touch, with ray cast) but the line renderer spawns ontop of the game object. the reason why it's far from the object is because its swinging at themoment

rich adder
#

you're just storing 2 numbers right now

slate badge
rich adder
abstract pelican
slate badge
rich adder
#

this is just a struct of 2 numbers

#

it does nothing by itself

#

its like expecting 123 to do something

violet topaz
#

this is the inspector but i cant assign anything to the Class

slate badge
rich adder
#

not actually doing anything with them

slate badge
#

I see

#

so what should i do instead

rich adder
#

reference the camera's transform

#

assign it to the position

rich adder
#

SelectClass1

violet topaz
#

A game Manager. do i need to switch it to the player?

abstract pelican
rich adder
violet topaz
#

yeah

slender nymph
# abstract pelican ?

well that's certainly not a helpful response. and yes, it is important to make sure that you have saved your code and that it has compiled in unity or else any changes you make won't actually be applied

rich adder
# violet topaz yeah

you should also remove Class = GetComponent<SelectClass1>(); since youre gonna assign it in the inspector

rich adder
slender nymph
abstract pelican
violet topaz
abstract pelican
#

now I can sit down while standing, now how do I make it sit down when pressed so that I don't pinch the button?

slender nymph
#

i already told you how to do that

abstract pelican
slender nymph
rich adder
abstract pelican
slender nymph
#

go read [this message again](#💻┃code-beginner message). i will not be writing the code for you. if you have questions about how to do something specific related to it, then ask a specific question. do not just respond with ?

violet topaz
#

@rich adder

rich adder
# violet topaz

ok are you dragging MainMenu object in that slot of ChangeClass

violet topaz
#

how do i do it if its in a differnt sence

rich adder
#

jesus h christ

rich adder
#

tbh you can just carry over the values from one scene to another

#

doubt you need cross references for this one, doing that in update is overkill

#

store it in an object that persist scenes, find it. Use singleton like it says

#

public int whatClass = 0;
you should probably getting into doing enums

public enum Classes { Scout, Medic, Assault } //eg
public Classes SelectedClass;
SelectedClass = Classes.Medic```
slate badge
#

@rich adder sorry for disturbing but i tried this but still didn't work, any suggestions?

summer stump
# slate badge

That is offsetting the transform of the object that script is attached to by a huge amount

#

Is that what you wanted?

slate badge
#

kind of like just teleporting there

summer stump
#

Just do
transform.positions = new Vector3(values)

slate badge
#

ah i see what was my problem, I previously used vector (the variable referring to the vector2 of the object) = new Vector2

#

Guess that doesn't work

#

and u have to directly call the position of the object

#

thanks an

#

man*

violet topaz
#

@rich adder I have no idea on how to do it can you help me again

rich adder
slate badge
#

ah i see

violet topaz
#

spawning in the player

#

i put what you told me in the script and it works but i dont know how to spawn the player

rich adder
violet topaz
#

i only have the code you gave me. i got frustrated and deleted the script.```cs
public class SelectClass1 : MonoBehaviour
{
public enum Classes { Scout, Medic, Assault }
public Classes SelectedClass;

public void ARClass()
{
    SelectedClass = Classes.Assault;
}

}```

rich adder
#

dont copy and paste script, read what the function does

#

its 1 line

#

its important you learn/read these things as you will be using them often, I dont have time to explain why they're useful just read description

violet topaz
#

@rich adder i got it but when i switch scene i cant get the camera. and its important to my player

#

error: MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

#

I will be back in ten if you answer

rich adder
swift crag
#

Always show your code. We cannot see your screen.

violet topaz
#
public class SelectClass1 : MonoBehaviour
{
    public enum Classes { Scout, Medic, Assault } 
    public Classes SelectedClass;
    public GameObject Assault;

    public void ARClass()
    {
        SelectedClass = Classes.Assault;
        if(SelectedClass == Classes.Assault)
        {
            Instantiate(Assault);
            DontDestroyOnLoad(Assault);
        }
    }
    

}
rich adder
livid nova
#

I'm trying to figure out a solution for when I change scenes. With each scene I need to load things like player position on load, Location of camera limits/clamps, name of the scene, and in each case it's going to generally be different. Is there a prefered way to do this? I have a general idea of how I could do this but it seems messy, where I would create a list or library and just pull from that

violet topaz
#

would i put the DDOL in the start or like a update

rich adder
polar acorn
unique violet
#

What is this error?

Assets/Scripts/PageSwitch.cs(4,17): error CS0234: The type or namespace name 'Unity' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

https://pastebin.com/0QnqPznc

rich adder
polar acorn
unique violet
polar acorn
unique violet
#

worked thanks

violet topaz
#

@rich adder something like this? ```cs
public class ChangeClass : MonoBehaviour
{
private SelectClass1 Select;
private void Start()
{
DontDestroyOnLoad(Select.Assault);
}

}```

livid nova
#

Not in the "I'm puttin the data on a JSON file" sense, but that I don't know how I should pull the data on load. Something like 'load scene' then based on the scene loaded the parameters are then loaded from a library.

last bane
#

how could i access data from other script in Unity Job without need to copy that data?

gaunt ice
#

Load to native/unsafe container and use pointer access

#

Or you are not talking about job system, then just reference the script

rich adder
#

what does your next scene setup look like ?(how do you spawn player etc.) @violet topaz

violet topaz
#

Sorry I got off but I will see tomorrow

last bane
# gaunt ice Load to native/unsafe container and use pointer access

something like this? i dunno how pointers work yet

class Chunk{
  public NativeArray<BlockType> VoxelMap;
}

class ChunkManager : MonoBehaviour{
  public public NativeArray<NativeArray<BlockType>> VoxelMaps;
}

[BurstCompile]
struct ChunkJob : IJob{
  public NativeArray<NativeArray<BlockType>> VoxelMaps*;
}
gaunt ice
#

Ijob is struct

#

And native array not support native array as its element

last bane
gaunt ice
#

Public unsafelist<something>* some ptr
Don’t remember to add the native disable unsafe ptr restriction attribute on it, then access it through some ptr->property

#

-> is operator of dereferencing pointer address

#

Actually i suggest you just copy the unsafe list into local variables then assign it back at the end of the job, continuously dereferencing address is quite expensive

last bane
#

i need to check neighboring chunks to update them properly, and i wanted to avoid copying voxelMap of all neighboring chunks

gaunt ice
#

Copying an unsafe list only costs 16 byte iirc,

last bane
#

whats "iirc"?

gaunt ice
#

If i remember correctly

#

Though for some readonly container i just copy the base addr and count to the job, i dont even need its capacity

last bane
gaunt ice
#

Copying the pointer is 8 bytes, count and capacity together is another 8 bytes

last bane
#

i think i will start learning C++ to understand these pointers 😂

#

i never seen someone using them in C#

gaunt ice
#

You pass the pointer only (low level reference) to the job

last bane
#

i saw only 1 guy doing Class that was working somehow like pointer

frosty rose
#

this is being called from a pointer enter event trigger inside a ui, how can i get the gameobject of the ui that the mouse entered?

public void MouseHover()
{
    moveTarget = true;
}
last bane
#

probably by using raycast from mouse pos UnityChanThink

frosty rose
#

really there is no paramater that describes the gameobject? i recently switched from roblox lua to unity and normally i wouldve done something like this

public void MouseHover(gameobject)
{
    if gameobject.Name == "Right" then
end

    moveTarget = true;
}
teal viper
#

I suggest checking out how MonoBehaviour and components in general work in unity.

frosty rose
#

ahh okay thankyou

topaz mortar
#

I'm making an idle game where the damage is automatic every x amount of time once combat starts
What functionality should I use for this?
Both damage and amount of time are variable

gaunt ice
#

Timer in update or coroutine

topaz mortar
#

Does this look good?
Would it prevent missed damage because of low fps?

    {
        timeToNextAttack -= Time.deltaTime;
        if (timeToNextAttack <= 0)
        {
            DamageMonster();
            float leftOverTime = timeToNextAttack;
            timeToNextAttack = attackSpeed - leftOverTime;
        }
    }```
gaunt ice
#

Timetonext attack+=attackspeed

#

Or you can check how many period is passed between frame and deal number of period*damage

topaz mortar
gaunt ice
#

Then you need to check number of period passed

solar tide
#

Hey, I've been trying to modify the material of a game Object through script.
But due to the face materials of my object being rendered by probuilder, I'm having a hard time changing it

#

Changing the main body material is working fine, but the face material change, I don't know what to write exactly to affect it(since it's created by probuilder, I don't know any of the probuilder codes)

gaunt ice
#

the error says enemymanager.cs

#

there is same error in your enemymanager.cs, then correct this script

inner marsh
#

this js came up next

cunning rapids
#

Guys

#

I need help with ADS

#

I don't know how to add aiming down sights to my weapons

#

Do I need some sort of animation?

gaunt ice
#

you dont need constructor for monobehaviour class

#

you shouldnt do that indeed

inner marsh
gaunt ice
#
class A{
  public A(){
  }
}

public A(){} is constructor of class A

#

show you script first , i may misunderstand the error

inner marsh
#
{
    public GameObject Wolf;
    // Start is called before the first frame update
    void Start()
    {
        int levelCurrent = PlayerPrefs.GetInt("levelCurrent");
        if (levelCurrent == 1)
        {
            Instantiate(Wolf, new Vector3(transform.position.x, transform.position.y, 0), transform.rotation);
            Instantiate(Wolf, new Vector3(transform.position.x - 15, transform.position.y, 0), transform.rotation);
            Instantiate(Wolf, new Vector3(transform.position.x, transform.position.y - 15, 0), transform.rotation);
            
        }
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}```
gaunt ice
#

i dont see anything wrong in this code...

inner marsh
#

idek whats wrong its called in the correct constructors

#

and like

#

should work

chrome hemlock
#

have you tried to restart the unity?

eternal needle
# inner marsh should work

did you save the script and is this the exact script you're using without anything cut out?
it also does seem like these errors happened way apart from each other

inner marsh
# eternal needle did you save the script and is this the exact script you're using without anythi...

entire script

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

public class EnemyManager : MonoBehaviour
{
    public GameObject Wolf;
    // Start is called before the first frame update
    void Start()
    {
        int levelCurrent = PlayerPrefs.GetInt("levelCurrent");
        if (levelCurrent == 1)
        {
            Instantiate(Wolf, new Vector3(transform.position.x, transform.position.y, 0), transform.rotation);
            Instantiate(Wolf, new Vector3(transform.position.x - 15, transform.position.y, 0), transform.rotation);
            Instantiate(Wolf, new Vector3(transform.position.x, transform.position.y - 15, 0), transform.rotation);
            
        }
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}```
inner marsh
inner marsh
inner marsh
#

ty

chrome hemlock
#

lol. alright.

#

sometimes that happened 🙂

#

and some tips, write 'wolf' in lowercase. if you using 'W', you'll messed up with function in the future. hope this help 🙂

cunning rapids
#

So much easier than I expected

inner marsh
#

should hopefully work

round scaffold
#

Guh

merry nebula
#

Any good tutorials to follow for a beginner 2D floating game? I unfortunately am just a newbie so everything is overcomplicated and i have like a week to finish a school project notlikethis

modest dust
#

YouTube or !learn

eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

modest dust
#

Anything will do if you only want to finish it

gaunt ice
#

a week for finishing one game is a bit short....

modest dust
#

Depends what kind of game

merry nebula
#

A very beginner-ish float game

modest dust
#

A simple one could be done easily in one day

modest dust
merry nebula
#

Imagine making flappy bird within a week with no graphics or animations and just make 3 different levels of it

#

Tho it shouldn't move like flappy bird

#

It should use gravity to move and float around the screen

#

If you don't press any buttons it just falls to the bottom of the screen

modest dust
#

So smooth movement instead of flapping

#

Just search up a flappy bird tutorial

merry nebula
#

Yeah, like flying part in geomtry dash

modest dust
#

and change the movement

merry nebula
#

Yeahhhhhhhhhhhhhhhhh a bit of then problem is the fact that I can't program that well, this assignment is a pain cuz i kinda have to force my way with it instead of taking my time learning it

modest dust
#

Yeah, so follow a flappy bird tutorial

#

If you want a hand-made map then make a background scroller

#

And look up how to make a smooth fly movement

merry nebula
#

Yeah I will basically need geomtry dash type of game but only the flying part

#

I assume you did play geomtry dash ._.

modest dust
#

I did

#

For a few minutes

merry nebula
#

Ahhh

modest dust
#

But I know what you mean

merry nebula
#

A okay

#

I'll do what I can

modest dust
#

Good luck

cunning rapids
#

Where is the Loop Time box to make the animation play infinitely?

chrome hemlock
#

you can check in animation file and tick "loop time"

tiny terrace
#

is there a way for gpu profiling when testing on mobile?

lone sable
#

So, I want to play a AudioSource on disable. Which obviously creates Can not play a disabled audio source error.

What would be a good solution to this? I could generate a prefab/new game object and play it there, but, I feel like there must be a better solution?

lone sable
#

I would have figured PlayClipAtPoint is what I want, but. Turns out I can't set the spatial blend/curve on it... So there goes that option.

solid kite
#

I'm trying to add a force on a rigidbody perpendicular to current velocity. It doesn't matter what direction it's just to test something

#

Why isn't this working?

fossil drum
# solid kite

Does it even call this piece of code, and can you debug.log the velocity you are adding?

solid kite
#

it does 100%

#

yeah i'll debug.log it

quasi birch
#

Try Vector3 perpendicularVelocity = new Vector3(-rb.velocity.x, rb.velocity.y, rb.velocity.z)

#

Then addforce to that variable?

solid kite
#

I think my approach is completely wrong

#

i'll try that

#

@quasi birch it's doing the same thing, just speeding me up

fossil drum
#

You don't AddForce to a variable though? You AddForce to a rigidbody that has a velocity.

solid kite
#

if my current velocity is north, my new one should be east, or west

fossil drum
#

The vector you create is either 0 or something weird.

#

Oh, you say its speeding you up UnityChanThink

quasi birch
#

Just try adding force, transform.right?

solid kite
#

shouldn't be transform though should be the right of my velocity

#

would it work if i did

fossil drum
#

Transform.right is just a vector pointing right of the transform of length 1, sure you can use that.

solid kite
#

but doesnt that depend on the rotation of my player

fossil drum
solid kite
#

@fossil drum I want to get vector 2 from vector 1

#

I got it nevermind, thanks

tough flint
#

Guys I've been having a slight problem with my character movement, it does not adpat to the camera position, so when im pressing W it will go foward and S backwards etc... but if i rotate the camera and look back W will still make me go forward instead of adapting and going back, if anyone could help me I would be thankful, here's the code I used (This is the player movement code).

using System.Collections.Generic;
using UnityEngine;

public class playerMovement : MonoBehaviour
{
   Rigidbody rb;
   [SerializeField] float movementSpeed = 6f;
   [SerializeField] float jumpForce = 5f;
    // Start is called before the first frame update
    void Start()
    {
       rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
       float horizontalInput = Input.GetAxis("Horizontal");
       float verticalInput = Input.GetAxis("Vertical");
       rb.velocity = new Vector3(horizontalInput * movementSpeed, rb.velocity.y, verticalInput * movementSpeed);

       if (Input.GetButtonDown("Jump"))
         {
          rb.velocity = new Vector3 (rb.velocity.x , jumpForce, rb.velocity.z);
         }
    
       
      ```
cosmic dagger
#

It doesn't know which way its facing or rotation in relation to the player . . .

tough flint
tough flint
wooden minnow
#

can someone help me understand how Mathf.Clamp() works

#

specifically the minvalue and maxvalue parts

keen dew
#

If the number you pass to it is smaller than minvalue, it returns minvalue. If it's bigger than maxvalue, it returns maxvalue. Otherwise it returns the original number.

wooden minnow
keen dew
#

It has nothing to do with vectors or quaternions

wooden minnow
#

ok

keen dew
#

It's a method that takes in 3 parameters

wooden minnow
#

ok

#

ok so, if i want to clamp my Y value of an object from where its currently is would it be like

i_suck_at_naming_variables = Mathf.Clamp(object.transform.position.y, object.transform.position.y-minvalue, object.transform.position.y+maxvalue)``` ?
somber wren
#

hello guys! i have a 3d spider walking on the terrain. But somehow it goes throught spheres, idk why

somber wren
#

i mean there, there is no point of clamping

#

nevermind

wooden minnow
somber wren
#

your value will always be between min and max

#

what do you want to do ?

keen dew
#

Don't subtract the values from the current position. Just pass in the limits you want

wooden minnow
somber wren
#

min and max

wooden minnow
#

wait actually

somber wren
#

just put them as they are

wooden minnow
#

i made a mistake nvm

keen dew
#

What is the problem you're trying to solve

wooden minnow
#

clamp an object's position or/rotation to a certain value (in this case -30, 30) while considering its Y value

keen dew
#

Then your limits are -30 and 30, just pass those values

somber wren
#

i still dont understand the second part xD

wooden minnow
#

what if my objects current rotation is 0, 60, 0?

#

wouldnt it clamp it to 0, 30, 0?

keen dew
#

That's what you wanted?

wooden minnow
#

no

#

so
i want to take an object's rotation value at one specific time(lets just use like 0, 110, 0 for an example) and then clamp it for -30 degrees and 30 degrees on its Y axis while considering its current rotation so itll be clamped between
x, 80/140, x
with x being an unclamped value

somber wren
#

you know what is "clamp" right ?

wooden minnow
#

does it have another meaning besides Mathf.Clamp()?

keen dew
#

Well then you save the values at the specific time you want and use them as min and max later

somber wren
#

clamp means "if im under minvalue, i become equal to minvalue, if im above max, i become equal to max. And if im in between min and max, i stay as i am"

#

yeah or you wanna use them later ?

wooden minnow
#

ok

somber wren
#

why raycast is going through, help :'(((

cosmic dagger
cosmic dagger
solar tide
#

Hey, I've been trying to move my instantiated object to hand, I was trying to get script component attached to the instantiated object and fire the method from here but for some reason, it just doesn't work.

You can't trigger a method from a different script or it has something to do with it being an instantiated object?

I can move it raw by changing the transform.position of the object but I can't get the component and use methods from the component I got(although the editor shows that I did get access to the component during runtime)

languid spire
#

post the MoveToHand method code

solar tide
languid spire
#

ok, so that is not actually doing anything

solar tide
#

what did I do wrong?

languid spire
#

you say to want it to move but there is no movement code in there

solar tide
#

the desired position creates the movement

languid spire
#

how?

solar tide
#

This script is attached to the instantiated object

#

discord is loading

languid spire
#

but how does desiredPosition affect transform.position?

solar tide
dawn sparrow
#

every 10 or so times i stop the application i get this screen infinitely

#

have to force-stop unity and it sometimes causes me to lose progress, i've tried searching up the issue but no dice

languid spire
solar tide
languid spire
#

should be fine unless something else is modifying desiredPosition

polar acorn
solar tide
#

oh yeah, the start function in GenUnit says gameobject.transform.position = desiredPosition

#

But shouldn't the new functions overwrite the old, my card movement on other script is comepletely fine

languid spire
#

which will run after MoveToHand is called

polar acorn
#

I feel like we're missing a lot of key information here. Might be good to post the full scripts instead of single functions

tawny hearth
#

i just launched my project and have all these errors. how fucked am i? 🙂

swift crag
#

I've seen this issue several times. For some reason, one of your packages just...refuses to see another one (or itself, in this case)

#

You can probably just remove the Test Framework package, from the package manager window

tawny hearth
#

it is a dependency from a bunch of crucial packages so i can't remove it sadly

swift crag
#

Have you done a "Reimport All" yet?

#

alternatively, just deleting the Library folder entirely

#

that's what I reach for first when this kind of thing happens

tawny hearth
swift crag
#

right click in the Project window

#

or open the Assets dropdown in the menu bar

gloomy timber
#

Hello,
I've a RTS project on Unity and wanna talk about settings and programming configurations.
I Kinda know how to program but need to be sure how to set script and organizing stuffs,
which problems to avoid etc.

tawny hearth
solar tide
#

Okay, time to ask you guys about basic math(I successfully solved the previous problem.)

How do you increase a value by 1 everytime this method gets run?

#

I can't believe it is so hard to write such a simple concept

#

Originally it was CardsinHand += 1 but that only gets read once and sets it to 1 and doesn't go higher

rotund bronze
#

try debug.log it to see it get call at the right time

solar tide
#

yeah, I am doing that.
I don't know how to do the math part

#

I'm pretty sure the math is wrong otherwise it should just increase

rotund bronze
#

cardsinhand+=1; shoud do fine not sure whats wrong with that

gloomy timber
swift sedge
buoyant knot
#

CardsInHand += 1 should work. It’s also equivalent to CardsInHand++. If the CardsInHand doesn’t keep going up, then that means either: 1) the ++ isn’t actually getting called, or 2) something else is setting it back down

polar acorn
buoyant knot
#

the whole PreviousInHand is unnecessary imo

polar acorn
cosmic dagger
# gloomy timber thanks for the reply RandomDiscordInvader(), for configuration I mean how can I ...

oh, that depends on how to design or build the game. there is n one solution for number of scripts. it solely depends on what you add to your game, like how you build/architect your units, and what type of systems you create

if you haven't built anything yet, i suggest looking at tutorials since an RTS is a huge undertaking. programming is iterative; your first solution will not be your last or final implementation of that specific feature . . .

buoyant knot
#

i would select cardsinhand and ctrl+R/cmd+R to find all the references to it

#

to see if something else is changing it

#

specifically, on the setter

#

i also think giving CardsInHand a setter is unnecessary

#

I assume this script is in a card’s class or something?

#

there should be a hand which has something like a List<Card> hand; and then you just do hand.Add(this card);

#

and if you want the hand size, use hand.Count

wintry quarry
solar tide
#

I got it

#

It's because I put CardsinHand inside my General Unit script.
Every Unit has it's own Cards in Hand and that's why it wasn't increasing

#

thx for the tips guys

wintry quarry
buoyant knot
#

what I’m getting at is; each unit probably needs to know which cards it has in its hand

#

so you need a list of cards tied to each unit, and you can call .Count on that list to know how many cards are in that unit’s hand

cunning rapids
#

Why is this error showing up even if everything looks correct?

swift crag
#

Those are states in the first screenshot.

#

Those are not parameters.

frosty hound
#

Of all those screenshots, you failed to show your trigger

swift crag
#

Parameters appear in the "Parameters" list.

#

These four rectangles are animator states. You can directly enter an animator state with Animator.Play, if you'd like.

#

Animator.SetTrigger is used to set a trigger parameter.

Parameters are used to control transitions and blend trees.

cunning rapids
#

Ah understood

#

How do I modify my script to access the animator state?

cunning rapids
swift crag
#

you don't need to 'access the animator state' here. If you just want to switch to a specific state on command, use Play("theStateName")

polar acorn
#

Because it doesn't

shadow flame
#

what the normal fov for a camera

swift crag
#

Directly playing states is perfectly reasonable, although it does mean you're doing everything manually.

cunning rapids
swift crag
swift crag
#

unity's default appears to be a vertical FOV of 60, which is around...90 horizontal, at least in my setup

#

I am not familiar with why you'd use vertical over horizontal.

shadow flame
#

some thing is wrong with it

#

1 sec

swift crag
#

explain your problem, then

shadow flame
#

why is it like this

cunning rapids
swift crag
swift crag
polar acorn
cunning rapids
swift crag
#

Transitions can look at parameters to decide if they can be taken.

#

For example, you can have four animator states in a row. The first state can have a transition to the second state that depends on a trigger.

#

The other two transitions can be unconditional.

#

Setting the trigger would play states 2, 3, and 4 in sequence.

#

So, for example, you might set a trigger to make the weapon reload animation play

#

When it finishes, you can automatically transition back to the idle animation.

#

That way, you don't have to manually play both the reload and the idle state.

cunning rapids
#

Interesting

#

Thank you for this insight

cyan wigeon
#

Having bit of an issue setting up Analytics for Unity:
My code contains:
using UnityEngine.Analytics;
And I tried to call even like so:
AnalyticsResult result = Analytics.CustomEvent("Skin Purchased" + skinToPurchase.name + " : " +skinToPurchase.characterId);
Debug.Log("Analytic result: " + result);
Yet I get this response:

#

Is there some setup thats incorrect ? ThinkSpin

cunning rapids
#

I implemented that

#

Sometimes the animation plays, sometimes it doesn't

#

This is the reload coroutine

cyan wigeon
#

theres usually some other state that blocks it from working properly or gets straight away overriden by a different state

cunning rapids
cyan wigeon
#

ideally have animator on 1 screen and game on another

#

and play it but keep an eye on what happens

#

in animator

#

that will let u troubleshoot if the transitions flow as u expect them to and what is currently being executed

cunning rapids
#

Ah I see

#

Absolutely brilliant

#

It seems that the problem is that the animation stays at the end of its playing time

#

I'll screen record this

shadow flame
#

why wont .FindGameObjectWithTag come up?

cyan wigeon
#

do other auto completes that are unity specific work ?

cyan wigeon
verbal dome
#

It is a static method too so not sure if it should show up there

wintry quarry
livid nova
#

Unity is crashing when I try to call a scene
I'm pulling data from a JSON file based on the previous save.
Any help appreciated

shadow flame
#

thanks

wintry quarry
cunning rapids
# cunning rapids Here

It does seem like the reloading is working since when the animation doesn't play you can't spam

#

It's just that the animation is stuck at the end of its play

#

unless another animation takes over

livid nova
cyan wigeon
cunning rapids
cyan wigeon
#

or to some empty state

#

depends what you aim to do exactly

cunning rapids
#

Like this?

#

Added a transition

cunning rapids
cyan wigeon
#

ye that will return u back to idle once those animations stop playing

#

alternatively u can point them to "exit"

#

as once exit concludes

#

it goes back to "entry"

#

either way should work fine I think

#

empty state with no return is usually for stuff like death animation

#

because u dont want nothing else to happen once it triggers(well that depends on a game I guess)

livid nova
wintry quarry
#

In some script in the new scene

cunning rapids
#

Works perfectly

cyan wigeon
livid nova
winged ember
#

how can I initialize an array of objects using the default constructor?

winged ember
#

oh no...

#

thats a long for loo[

wintry quarry
#

it's a super short loop

#

But let me ask you a different question. Why are you using a class instead of a struct here?

winged ember
#

it's 32768 itterations

wintry quarry
#

indeed

winged ember
timber tide
#

classes are cool

wintry quarry
# winged ember idk

if you use a struct you don't need to do anything other than the second screenshot

winged ember
#

is there a reason not to?

wintry quarry
#

A class will use a bit more memory here too

#

and need to be garbage collected later

cunning rapids
#

Guys

#

How do I make my pistol game object play its animation for sprinting when the only sprinting check is done on the PlayerMovement script?

#

Which is obviously attached to the player, not the pistol

winged ember
#

converted to struct, got this error

obtuse oar
#

i keep getting this when trying to add my script to an object in the game, I have modified and saved the script and the class name does match the file name, is there something i'm missing?

polar acorn
cunning rapids
#

Is the class name of the script the same as the script name?

obtuse oar
fossil drum
#

Is Button even allowed? Wouldn't that give a conflict with Unity's Button UnityChanThink

polar acorn
obtuse oar
polar acorn
#

Show a screenshot of your console

cunning rapids
obtuse oar
cunning rapids
#

Show us the Unity console instead

obtuse oar
#

oh the errors were hidden for some reason, this is the error: "Assets\Scripts\Selection_Settings.cs(18,29): error CS1061: 'Button' does not contain a definition for 'interactable' and no accessible extension method 'interactable' accepting a first argument of type 'Button' could be found (are you missing a using directive or an assembly reference?)"

polar acorn
obtuse oar
#

why do i need that? i just want a simple script to be a button, all it does rn is just print to the console

short hazel
#

You named your own class Button, so it's picking up that one instead of Unity's Button

obtuse oar
#

oh, well that's annoying

polar acorn
obtuse oar
#

my b lol

ionic pike
#

yo guys does anyone how can i make my itens stack when i pick em up to the inventory?

ionic pike
#

i mean they do stack but i still figuring out a way for them to stack when entering the inventory

#

when i pick them up

swift crag
#

you'll have to check if the inventory contains a compatible object

short hazel
#

Loop through all the slots, if the item in the slot is the same as the one that is about to be added, add it

swift crag
#

you may have to do this repeatedly if you pick up a big stack

short hazel
#

^ + discard items if inventory is full

swift crag
#

Note that this is going to have nothing to do with the hierarchy. There's no magic button to make the icons "stack" together or something.

ionic pike
#

ok i already know what too do

#

this shit is gonna take a long ass time to make

short hazel
#

For each item stack in the inventory
If the item is compatible, and the slot is not full
Add the most possible items to the slot
End
Loop
Drop the remaining items if any, the inventory couldn't hold more
That's how the loop should look like

ionic pike
#

oh

#

i get it

#

thx

#

good help

hollow zenith
#

How do I make an object move along the Edge Collider 2D without slowing down?

        rigidBody2D.velocity = new Vector2(1f, 0f);

This will make it float to the right
I have the player object + collider with a slippery material(0 drag)
Player object has 1 gravity scale and 0 drag.

rich adder
#

haven't done too much 2D so take it with grain of salt

zealous oxide
#

hey friends. i've got a melee character controller that has its recoil settings influenced by a child "combat entity". character controller is responsible for movement & stats etc, whilst the combat entity handles attack functions. https://hastebin.com/share/ovarozebuz.csharp heres the player script. https://hastebin.com/share/ucuhenawub.csharp heres the combat entity. i've got 2 issues atm. if my character attacks down, it recoils up regardless if it actually hit an enemy. i'm struggling to understand how i can get the combat entity script to properly tell the player controller script if it should be recoiling on the x or y axis when an enemy is hit. the other issue is that if the player hits an enemy to its left or right, i'd expect a respective recoil in the opposite direction on the player, but it doesnt do anything, actually, regardless of the force I apply

hollow zenith
#

is there something like "forward" in 2d?

rich adder
#

depending which way sprite faces / orientation of your game (topdown vs sideview)

hollow zenith
#

yeah I want the sprite to always be touching the edge with the bottom/legs

rich adder
#

doesn't brackys have something like this with that line rider game?

#

maybe its the same process

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

manic ether
#

Following a tutorial for the new input system, this zoom control is acting weird. Each click of the mousewheel sends it to max or min, continuous scrolling makes it kinda jitter in place. Sometimes one direction will stop working entirely until you scroll the other direction first... Tutorial said to normalize the vector 2 in processors to stop it jumping to max/min, but that didn't help.

    {
        if (context.phase != InputActionPhase.Performed)
        {
            return;
        }
        // Adjust the current zoom value based on the direction of the scroll - this is clamped to our zoom min/max. 
        CurrentZoom = Mathf.Clamp(_currentZoomAmount - context.ReadValue<Vector2>().y, ZoomMax, ZoomMin);
    }```
And in late update:  
```  _actualCamera.transform.localPosition = Vector3.Lerp(_actualCamera.transform.localPosition, 
        _cameraPositionTarget, Time.deltaTime * _internalZoomSpeed);```
eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

shadow flame
#

why no work

short hazel
#

We need at least the error message.

glossy eagle
#

Hi. One question, is there something like transform.TransformPoint but without taking into account the transform Z rotation please? like as if it was in a 2D plane kinda

languid spire
#

you dont have a variable rb decalred or it is the wrong type

hollow zenith
shadow flame
short hazel
#

You cannot put a Rigidbody into a Rigidbody2D

#

As you're in a 2D project, .platformRb should probably be a Rigidbody2D.

#

Same for rb

#

The types must match, here they don't. You're trying to put a square into a round hole

shadow flame
#

thanks

#

i forgot to put in 2d at the end

obtuse oar
#

how can i grab the child of an object? google says to use the getchild method but i'm not seeing that as an option

short hazel
obtuse oar
#

ohhh

#

does the object returned equal the whole child object or just the child's transform?

#

i kinda just answered my own question when trying to use it, how can i get the whole child

zenith cypress
#

The transform, but you can get the object with .gameObject

obtuse oar
#

not just the transform

short hazel
#

Intellisense will tell you that as you type the method name

obtuse oar
#

and now how do i grab the TMP text component off that with getcomponent? i just dont know the type i am supposed to use

short hazel
#

TMP_Text

swift crag
#

TMP_Text covers both TextMeshPro and TextMeshProUGUI. It's the ideal choice.

#

You don't really care whether or not this is UI text, and it's easier to type, too.

obtuse oar
#

i tried that already but got this:

#

oh the T isnt capital lol

#

same issue

short hazel
#

Let your code editor fix it for you, click the light bulb icon

#

It will give you suggestions

obtuse oar
#

oh wth, i have never seen a structure like that before, the type is TMPro.TMP_Text

#

TMP is actually the weirdest thing

short hazel
#

That, or using TMPro; at the top

swift sedge
#

its literally what classes and namespaces are

short hazel
#

Which should be the first suggestion in the list

swift sedge
#

like "System.Serializable"

obtuse oar
swift sedge
short hazel
#

Using a directive

using TMPro;
// ...
private TMP_Text _text;

Fully qualifying the name

private TMPro.TMP_Text _text;

Both are valid, but the first one is better to use in the case you need to use stuff from TMPro multiple times

obtuse oar
#

yeah, just never knew you could literally do the whole TMPro.TMP_Text thing

#

what's the reasoning for the underscore in front of ur variable? i've seen it a lot in more professional examples of coding but never really understood it

#

same with like m_

short hazel
#

It's a convention so you don't mix them up with local variable you declare inside methods

#

The m_ is a residue from C++ and isn't official for C#, but Unity still uses it

obtuse oar
#

oh so does the underscore denote that it's a class viarable

short hazel
#

Correct

obtuse oar
#

gotcha, the more ya know

swift sedge
#

like s_ is for static

obtuse oar
#

i would like to duplicate this object onto others now but when i do so it does not move the rect transform at all meaning they all display at the same location as the first and not respective to their parent object, is there a simple way to do this in the script?

#

i figured it out, improper pasting on my end

obtuse oar
#

would (int) Mathf.Floor(Random.Range(0, 9)); be the best way to get a random int from 0 to 9 inclusively with even odds for all values?

#

or would implicit int casting already cover the floor bit

polar acorn
#

Int random is max exclusive

obtuse oar
#

oh okay

polar acorn
#

And casting to int will truncate decimals, it just ignores them. This is slightly different from a floor in that positive numbers are floored, negative numbers are ceiling'd

obtuse oar
#

so i should revise this to just Random.Range(0, 10); if i am setting an int equal to this?

river roost
#

(there's also Mathf.FloorToInt which removes the need to cast to int at the end)

obtuse oar
#

interesting

obtuse oar
#

across 3 boxes, each with 5 separate numbers I want to only have one similar number between the 3, the others are all random. The first pic is an example of how it is breaking right now, both 6 and 1 are present in all 3 boxes when the "correct number" is supposed to just be 6. The second pic is an example of what I mean with the number similar between them being 1. is there a simple way to do this that I am overlooking that is not looping over all the number to see what can/can not be put there?

violet topaz
polar acorn
#

that way you can never have three of a kind, and it's not always the third box that's "missing" a number

violet topaz
tight zenith
timber tide
#

You can start by not posting in every channel, thanks

tight zenith
#

Very helpful!

#

I posted in 2 channels, in actuality

swift crag
#

which is more than one, which is cross-posting.

languid spire
short hazel
#

Still one too many

swift crag
#

I would suggest moving this to #📱┃mobile , since you are having a problem with building for Android.