#💻┃code-beginner

1 messages · Page 413 of 1

willow scroll
#

Both can be gotten with the Random.Range method you've used before

rocky canyon
#
    public Vector2 maxPosition; // Maximum spawn position``` yes you should be able to assign these in the inspector
umbral rock
rocky canyon
#

debug randomPosition before u use it

#

right below this debug the value to see what shows in teh console..
Debug.Log(randomPosition);

willow scroll
rocky canyon
#
        GameObject spawnedObstacle = Instantiate(obstacleToSpawn, randomPosition, Quaternion.identity);```
his instantiate method uses the randomPosition
#

im not sure how they'd always be in the middle

umbral rock
#

look when i debug the randomposition

rocky canyon
#

unless his values in the inspector are set up wrong

#

ya, thats fine.. thats not middle

#

i see -4 in there

willow scroll
umbral rock
rocky canyon
#

well they need longer pipes. and more extreme values

willow scroll
umbral rock
#

yes but i dont understand what u mean by it, what is wrong with my code?

#

this is my spawner inspector

rocky canyon
#

i think its more of a setup issue

#

ur prefab should be something like this..

#

really long pipes off the top and bottom.. and a gap in the middle.. the middle point is ur position.. then u can position it anywhere on the Y

#

and the pipes will extend off the screen bounds

#

the green + is the pivot (center)

lone sable
#

Because I want it to travel a specific distance/do a easeInOutBack motion.

rocky canyon
#

or... if u dont want em on the bottom and top u can do the same w/ two prefabs

#

just make sure they extend farther down like the double version does

umbral rock
#

what? i dont understand, what should i do with my prefab?

willow scroll
umbral rock
#

its just the instantiate thats wrong? idk about prefabs but if u look at my game u can see pillars spawning in the middle of the screen wich shouldnt happen

#

how does that have something to do with prefabs?

willow scroll
rocky canyon
willow scroll
rocky canyon
#

i made 2 for example (1 for the top and 1 for the bottom) .. the pipe is a child and extends from teh center... and way off the screen

umbral rock
#

if i set the spawn values to 0 then the pillars spawn perfectly on top of my view wich i want, but i want them to also spawn at the bottom, thats why i use random.range, but the problem is that my pillars are spawning between 2 values wich is the result of my pillars spawning in the middle

rocky canyon
#

sooo when i set the position.. im setting that center position... no matter where i put it the pipe would extend off the edge of the screen

umbral rock
rocky canyon
#

no..

umbral rock
#

whut

rocky canyon
#

u can use the same spawner and chose to spawn w/e prefab

errant anchor
#

I would like to ask everyone for some help. I am a beginner and while learning a tutorial on making a character move, I found that when obtaining the input system values, the character automatically moves to the left as soon as I run the game, even without any input. The input values obtained in the red box in the screenshot show no input, yet the character still moves by itself. I also added a stick deadzone to the input, but the character still moves on its own without any input. I sincerely ask for everyone's help to find out what the reason could be.

rocky canyon
#

the main point is the prefab ROOT object.. is centered.. and the sprite then stretches from there down past the screen edge..

ivory bobcat
umbral rock
rocky canyon
#

if the edge of the pipe is really long.. it doesnt matter if u spawn it in the middle.

errant anchor
#

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.PlayerLoop;
public class PlayerController : MonoBehaviour
{
public PlayerInputController inputControl;
private Rigidbody2D Rb;
public Vector2 inputDirection;
public float speed;

private void Awake()
{ 
    
    inputControl = new PlayerInputController();
    Rb = GetComponent<Rigidbody2D>();
    

}
private void OnEnable()
{
    inputControl.Enable();
}
private void OnDisable()
{
    inputControl.Disable();
}
private void Update()
{
    
    inputDirection = inputControl.gameplay.Move.ReadValue<Vector2>();
   
}
private void FixedUpdate()
{
    move();
}
public void move() 
{
    Rb.velocity = new Vector2(inputDirection.x * speed*Time.deltaTime, Rb.velocity.y);
    //人物翻转
    int facedir = (int)transform.localScale.x;
    if (inputDirection.x > 0)
        facedir = 1;
    if (inputDirection.x < 0)
        facedir = -1;

    transform.localScale = new Vector3(facedir, 1, 1);

}

}

rocky canyon
#

the pipe would extend off the page...

errant anchor
#

code is here

rocky canyon
#

ur random range is working..

#

in the code.. and in the clip u shown.. its not broken

ivory bobcat
#

How to post !code (use the large code blocks guide rather than the inline guide if you've got more than a few lines of code to share)

eternal falconBOT
safe radish
umbral rock
rocky canyon
#

adjust ur range...

#

maybe have 2 ranges.. 1 range for the top section of the screen

#

and 1 range for the bottom

#

if u dont include the middle it'll never spawn in the middle

umbral rock
#

aah, so that u have minPosition/max for the top section and a minPosition/max for the bottom

rocky canyon
#

yes

#

and maybe have 2 functions to call (thats the easiest)

#

or.. u can randomly pick 1 of those ranges even 😄

umbral rock
#

i have a tutorial here and he just adds a transform.position and then + the ranges

#

could that work in my project?

rocky canyon
#

if it works for him it'll work for u

umbral rock
#

ait, i'll try it, thanks alot for the help, cant thank u enough!

rocky canyon
#
    private void Spawn() {
        Vector2 randomPosition;
        bool spawnAtTop = Random.Range(0, 2) == 0; // Randomly decide whether to spawn at the top or bottom

        if (spawnAtTop) {
            // Generate a random position within the top bounds
            randomPosition = new Vector2(
                Random.Range(minPositionTop.x, maxPositionTop.x),
                Random.Range(minPositionTop.y, maxPositionTop.y)
            );
        } else {
            // Generate a random position within the bottom bounds
            randomPosition = new Vector2(
                Random.Range(minPositionBottom.x, maxPositionBottom.x),
                Random.Range(minPositionBottom.y, maxPositionBottom.y)
            );
        }
#

altho u creating random X positions too

#

not sure how that works out for the type of project ur doing

errant anchor
rocky canyon
#

left and up

errant anchor
# errant anchor this is my debug log

code like this private void Update()
{

 inputDirection = inputControl.gameplay.Move.ReadValue<Vector2>();
 Debug.Log("inputDirection: " + inputDirection);

}

ivory bobcat
errant anchor
errant anchor
ivory bobcat
errant anchor
ivory bobcat
#

Show your action composites and bindings. Here's an example

normal mortar
#

anybody know how i can check for a collision and than delete the gameobject?

#

pls ping me if yes

ivory bobcat
normal mortar
ivory bobcat
#

Also, this should be done in some collision physics callback function

#

You probably ought to lookup a unity tutorial on collision

normal mortar
#

alr

ivory bobcat
errant anchor
ivory bobcat
fading sluice
#

is there a way to tell whether a button is pressed or not via script? (not through editor)

i swear there was a button.clicked condition

ivory bobcat
errant anchor
sleek gazelle
#

Hey I have a problem, I don't understand why this doesn't work. What should happen is that class 1 start the GameStart function in class 2 and then in class 2, the GameStarted bool is set to true. However when I try it, it sets true in the first class but not in the second so the game just never starts

    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !GameStarted){
            GameStarted = true;
            var instance = new DriftComponent();
            instance.GameStart();
        }
    }
    void Update()
    {
        if (GameStarted){
          //never happens to be true for some reason
           ...
        }
    }

    public void GameStart()
    {
        MoveSpeed = 50;
        Drag = 0.98f;
        SteerAngle = 20;
        Traction = 1;
        GameStarted = true;
        Vector3 MoveForce;
    }
ivory bobcat
sleek gazelle
fading sluice
#

i dont think this is the right one lol

ivory bobcat
#

Where are you adding the component? Is the game object with the new added component active in the scene? Is the component enabled? @sleek gazelle

fading sluice
#

left is the name of a button

#

i wanted somehting like

if (left.clicked) 
{
  Left();
}
cosmic dagger
fading sluice
#

should i use OnClick instead

#

wait no i cant read

cosmic dagger
#

it is a method and it does not return a value. that should not even compile . . .

fading sluice
#

oh

digital kelp
#

Something about this is causing a memory leak it seems. Anyone got any idea why?

>     private void AddTechElement(TechType tech)
>     {
>         var itemUI = techSlot.Instantiate();
>         itemUI.Q<Label>("TechSlotDescription").text = tech.techDescriptionShort;
>         itemUI.Q<Button>("TechSlotButton").text = tech.techName;
>         itemUI.Q<VisualElement>("TechSlotImg").style.backgroundImage = Resources.Load<Texture2D>(tech.techImgPath);
> 
>         Button choseTechButton = itemUI.Q<Button>("TechSlotButton");
>         choseTechButton.clicked += () => ResearchTech(tech.techName);
> 
>         techListElement.Add(itemUI);
>     }
>     private void ResearchTech(string tech)
>     {
>         Debug.Log("Tech chosen:" + tech);
>         ResearchTech(tech);
>         AvailableTechs.Remove(tech);
>         CompletedTechs.Add(tech);
>         techListElement.Clear();
>     }
eternal falconBOT
digital kelp
#

nvm, found the issue.....

#

I left ResearchTech() inside the function itself notlikethis

languid spire
#

then you weren't getting a memory leak you were getting a stack overflow

digital kelp
#

probs, I ain't got a clue

tight cradle
#

Hello guys, im new to this and Im following a tutorial, anyone knows why the squares (enemies) shows on the scene but not in game window? thanks

languid spire
digital kelp
#

Sorry, my bad. Saw a lot of people mentioning it in the results I got when searching up the error message

idle ginkgo
tight cradle
idle ginkgo
#

check the z position

#

of the objects

tight cradle
tight cradle
#

:))

late burrow
#

i know linerenderer points dont lag but it still scary to keep 1000 of them with thousands of points each preloaded

sleek gazelle
#
public void OnPointerUp(PointerEventData eventData)
    {
        //InfiniteMode?.Invoke();
        InfiniteMode(this, EventArgs.Empty);
        Debug.Log("The mouse click was released");
    }
#

Why do I get this error Object reference not set to an instance of an object about the this?

languid spire
#

because InfiniteMode is null ?

sleek gazelle
languid spire
#

Debug.Log it

swift crag
#

//InfiniteMode?.Invoke();

sleek gazelle
swift crag
#

you have commented out code that safely checks if InfiniteMode is null before triyng to invoke it

#

You have not given any context, so I have to guess that InfiniteMode is an event member

sleek gazelle
#

OHHHHHHHH

#

I understand

#

It works

#

Thanks

#
public void OnPointerUp(PointerEventData eventData)
    {
        InfiniteMode?.Invoke(this, EventArgs.Empty);
        Debug.Log("The mouse click was released");
    }
#

Did this and now I got no error

#

But the event is never catched anywhere 😢

languid spire
#

yes, because it does nothing if InfiniteNode is null. You have to ask yourself why was it null in the first place

sleek gazelle
#

Idk cause it exists here

    static void main(){
        var publisher = new InfiniteModeButton();
        publisher.InfiniteMode += InfiniteModeStart;
    }

    static void InfiniteModeStart(object sender, System.EventArgs e){
        Debug.Log("Event Catched");
    }
polar acorn
languid spire
#

that is the method declaration. not the event declaration

polar acorn
#

and an event with nothing subscribed to it is actually null

sleek gazelle
polar acorn
sleek gazelle
#

It is in it rn

#

void Start()
{
var publisher = new InfiniteModeButton();
publisher.InfiniteMode += InfiniteModeStart;
}

polar acorn
#

What is InfiniteModebutton?

swift crag
#

Show your entire script.

sleek gazelle
sleek gazelle
polar acorn
sleek gazelle
#

Hmmmm idk

languid spire
#

This makes no sense

sleek gazelle
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class GameManager : MonoBehaviour
{
    public static string Gamemode = null;
    public static bool GameStarted = false;
    // Start is called before the first frame update
    void Start()
    {
        var publisher = new InfiniteModeButton();
        publisher.InfiniteMode += InfiniteModeStart;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !GameStarted){
            GameStarted = true;
        }
    }
polar acorn
#

Do you have any errors in your console

sleek gazelle
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using System;

public class InfiniteModeButton : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
    public event EventHandler InfiniteMode;


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

    // Update is called once per frame
    void Update()
    {
        
    }

    //OnPointerDown is also required to receive OnPointerUp callbacks
    public void OnPointerDown(PointerEventData eventData)
    {

    }

    //Do this when the mouse click on this selectable UI object is released.
    public void OnPointerUp(PointerEventData eventData)
    {
        InfiniteMode?.Invoke(this, EventArgs.Empty);
        //InfiniteMode(this, EventArgs.Empty);
        Debug.Log("The mouse click was released");
    }
}
sleek gazelle
polar acorn
languid spire
#
var publisher = new InfiniteModeButton();
        publisher.InfiniteMode += InfiniteModeStart;

local variable, so goes out of scope

sleek gazelle
sleek gazelle
#

But I never get the "event catched" in the log

languid spire
#

cannot new a MonoBehaviour

sleek gazelle
sleek gazelle
polar acorn
languid spire
#

as uoi are not using Start or Update, yes

sleek gazelle
sleek gazelle
#

It sends this

polar acorn
#

You can't put it on any GameObjects

#

Presumably, you do want it to be one

sleek gazelle
#

Ah

#

Yes I want

#

It's a clickable button

polar acorn
#

So, what I am trying to get you to see is the error specifically saying that you cannot create MonoBehaviours with new

keen dew
#

My crystal ball says that there's an object in the scene that has this properly as a component, and that throws the error. newing is just an attempt at referencing it

polar acorn
#

And if you aren't getting that error, then you also don't have a GameManager in the scene

polar acorn
sleek gazelle
#

but idk how to do without new

sleek gazelle
#

I have no error but a yellow thing

polar acorn
sleek gazelle
#

That says:
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor ()
InfiniteModeButton:.ctor ()

polar acorn
#

Okay, it's a warning, not an error

sleek gazelle
#

I thought you were talking about big red thing sorry

polar acorn
#

but it is still a problem

sleek gazelle
#

Yeah sure

polar acorn
#

why not just reference the one you already have

sleek gazelle
#

Cause now I have an error

keen dew
#

When people were saying that doing new to a MonoBehaviour was a problem, it didn't occur to you that a warning that says "You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed." might be somehow related?

sleek gazelle
#

Non-invocable member 'InfiniteModeButton' cannot be used like a method.

sleek gazelle
#

sorry again about that

polar acorn
#

what is the line that gives this now

sleek gazelle
#

var publisher = InfiniteModeButton();

#

I removed the new

polar acorn
#

why are you trying to call it like one

sleek gazelle
#

Kinda new to C#

languid spire
sleek gazelle
#

I don't know all the syntax yet

languid spire
#

did you move the line outside of the Start method?

polar acorn
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

sleek gazelle
languid spire
#

you really do need to learn some C# basics

sleek gazelle
sleek gazelle
#

Thanks guys

#

🙏

summer stump
sleek gazelle
#

Thanks

languid spire
# sleek gazelle Thanks

one other word of advice, don't just blindly copy code, that road only leads to a world of pain

lavish jolt
#

Hello! When I load the scene, lighting breaks. How can I fix it?

polar acorn
swift crag
#

It's probably broken there too.

#

When you enter play mode, Unity generates lighting data for you if it doesn't exist.

#

It won't do this when you switch scenes, or at all in a build.

polar acorn
#

If it doesn't happen in a built version of the game, you can ignore it. I don't remember if they ever fixed that in a later version

swift crag
#

so you get a scene with no ambient lighting

#

You can go to the Lighting tab (window -> lighting or ctrl+9) and create a lighting settings asset. Uncheck both of the "global illumination" options and then hit Generate Lighting

#

this should be fast, since it's doing very little work

dreamy dune
#

i have a little pronlem so i have my transform for my muzzl flash on my gun but when i animate with the gun the game object doesnt move along

polar acorn
dreamy dune
#

i did

polar acorn
#

If it's a particle system, make sure it's simulating in local space

dreamy dune
#

its not a partical system its just a spawn locatuion of my cartrigde

queen adder
#

anyone tried using easysave for chunk load/unload system like in minecraft before?

hallow acorn
#

hey im trying to make a canon and i want it to shoot my prefabs. i managed to instantiate my object and apply a force to it but how can i automaticly add the force to the forward direction of my canon and how would i give it an angle so it doest shoot straight up forward?

polar acorn
hallow acorn
#

wdym just too setthe velocity of the prefab itself?

swift crag
#

No.

#

digi said to spawn the object and then set its velocity

#

the velocity of the newly-created object

hallow acorn
#

oh ok

hallow acorn
polar acorn
swift crag
#

Remember that Rigidbody.AddForce interprets the vector in world space.

#

So if you use a constant direction, it's probably wrong

hallow acorn
polar acorn
#

transform.forward gets the direction the object is facing

hallow acorn
#

transform.forward is a vector3 isnt it?

polar acorn
#

yes

hallow acorn
#

is there an easy way to modify the y axis? or better add the force at an angle?

polar acorn
#

I mean, it is facing the direction you want, right?

#

Just, like, use that direction

hallow acorn
#

if the canon is at x or z rotation 0 but the model itself is angled, its not exactly the correct direction

swift crag
#

How do you decide where to create the cannonball?

#

Did you add an empty "fire point" object?

hallow acorn
#

no it just spawns it at the pivot of the model which alligns with the start of the barrel. if the object get launched at an angle it flies through also the ship is far away so you wont notice it as it just fires at my island

swift crag
#

that sounds very awkward; rotating the cannon model would make it flip into the air

swift crag
swift crag
#

If the pivot point is at the end of the barrel, rotating the model will make its pin around the pivot point

hallow acorn
#

the pivot is centered but it happens that the barrel on the back just fits perfectly

swift crag
#

wheeee

hallow acorn
#

th closed end bro

swift crag
#

well that that sounds doubly wrong

#

you want the cannonball to appear at the end of the barrel

swift crag
hallow acorn
swift crag
hallow acorn
#

ok but if i have my cannon script on the empty object, and i add the force to the referenced projectile does the force direction change depending on the rotation of the empty obejct?

swift crag
#

if your force vector is based on the direction the object is facing, yes

#
var force = firePoint.forward * shotForce;

for example

hallow acorn
#

so using transform.forward would even launch the projectile on the x rotation i want?

swift crag
#

transform.forward is a world-space vector that tells you which direction is "forward" for transform

#

notably, that would be the transform of the object your component is attached to

#

(that's what the transform property gives you)

#

So that would be wrong, because you'd be using the transform of the cannon itself, not the fire point

hallow acorn
#

bruh but when i attach the script to the firepoint?

swift crag
#

It would then be correct.

#

you don't have to "bruh" me. I am trying to explain what will and won't work.

hallow acorn
#

but thanks i apreciate your help

hallow acorn
swift crag
#

I would want to put the cannon component higher up in the hierarchy

hallow acorn
#

but i need it to be a child of my ship cause it gets rotated to a target point in my scene where the projectiles should be launched at

swift crag
#

Right -- you might do this

  • Cannon <-- just the "cannon fire" component
    • Model
      • Fire Point
hallow acorn
#

i think i dont understand. i have my ship, and my cannon as a child, so it rotates when the ship rotates

swift crag
#

Yes, so you'd parent Cannon to the ship

#

Parenting the model to an empty object makes it easy to adjust the position and rotation of the model

#

it lets you change the apparent pivot point for when you rotate the entire Cannon

hallow acorn
#

i dont get it xd

#

i have my ship on top, bc it gets rotated the way the cannons should. the cannons are the childs of my ship.

swift crag
#

Yes.

  • Ship
    • Cannon
      • Model
        • Fire Point
hallow acorn
#

ohh so the cannon is a parent with the firepoint and the model "childed" to my ship i think i get it

wanton kraken
#

why does this code insist that 'PlayerMask' doesn't exist when i try to use it in raycast?


    void Start()
    {
        LayerMask PlayerMask = ~LayerMask.GetMask("Player");
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R) == true) {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up, 3f, PlayerMask);
            Fire(hit);
        }
languid spire
#

because PlayerMask is a LOCAL variable to Start

wanton kraken
#

ah oops

#

thanks!

pale fulcrum
#

Hi, I am trying to understand unity by building endless runner.
But can't understand why the path spawn at a distance from the player ? Help please.

eternal falconBOT
rich adder
shrewd pivot
#

how do i code in unity? i got it installed properly and want to code a sidescrolling adventure game

willow scroll
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

shrewd pivot
#

Oh okay

pale fulcrum
mild plank
#

Hi, I know this isnt exactly code, but how would you accomplish having a prefab house with only 1 room? (player would have access only 1 room, others will be just nothing - for less lag) - how do I make the windows look the same for the 1 real room and the other fake rooms from outside, but from the 1 room being still able to see outside normally?

lone sable
#

If I want to edit material properties via a script, in both runtime, and edit mode (Via [ExecuteAlways]) Whats the proper way to handle it?

polar acorn
near raven
#

Hello, I've been looking for the right room to make a post asking questions about Unity development but I can't find it. Does anyone know it, please? There is 'DOTS" but i don't think that'sthe right one

willow scroll
polar acorn
near raven
near raven
polar acorn
near raven
# willow scroll What question?

My question is what is DOTS. Is it that ? : https://unity.com/fr/dots
That way I know if I'm off-topic or not in relation to the problem I want to explain so that people can help me.

In fact, the problem I'm having with Unity is so long to explain that I'd have preferred to present it in a room where you can make posts. And "DOTS" seemed to be the most suitable. But I think this not the best room for that.

Unity

La pile technologique orientée données (DOTS) de Unity est une combinaison de technologies et de paquets qui offre une approche de conception orientée données pour la construction de jeux dans Unity.

near raven
willow scroll
#

And, yes, the link you've sent is about DOTS

polar acorn
languid spire
near raven
near raven
# languid spire why would you think that a question about <#1062393052863414313> does not belong...

I wasn't clear, but basically I've got a problem with Unity. And on the discord server where I usually ask for help, there are dedicated room where you can only make posts. We don't ask for help on threads like this one.
My mistake was to adopt the same logic here. So I was looking for a room where we make posts to ask my question. I found "DOTS". I wasn't sure I could present my problem with Unity here because the term "DOTS" was unfamiliar to me. And on "DOTS", I didn't dare make a whole post to find out what it meant because the question seemed silly to me.

#

But now I've got my answer thanks to @polar acorn. I'm going to go to the other room. It's a shame we can't make a dedicated posts. Thanks again to everyone! Sorry to have polluted the discussions with my stupid intervention

languid spire
atomic yew
#

Hello friends, I have a problem. My game works fine in the editor, but when I compile the game for PC or Android, most everything works, but I guess I can't get the information I saved in json format as I want. When I compiled it for PC today, I entered the game and caught an animal, saved the game and logged out. When I entered the game again, I could not access some of the things I saved, for example, the Transform location was in the place I saved, but there was no animal caught. But it was recorded in json format. When I went into the editor again and looked, I could see everything I saved in the compilation there. I think my problem is that it doesn't read from json because I didn't make certain settings. Can one of you send me a screenshot of the player settings or tell me if you guess the source of the problem?

slender nymph
#

don't crosspost

atomic yew
summer stump
near raven
near raven
hallow acorn
#

if i use transform.forward for sth how is forward defined? like which axis?

polar acorn
#

It's the object's Z axis

#

Blue arrow

hallow acorn
#

ok

#

ty

digital warren
#

anyone knows how to fix this?

hallow acorn
slender nymph
#

that isn't what they were asking for. but what they were asking for wasn't even necessary anyway. we'd need to actually see your code to determine what is wrong if you're too lazy to go through the steps in the link i gave you

hallow acorn
full kite
#

what changes does a pivot make?

digital warren
#

._.

full kite
#

like sometimes the image goes up and down but why not every single time?

digital warren
#

must be when i login must be enter the game but its not

#

using photon

hallow acorn
# digital warren game server

send a screenshot of the inspector pls. theres propably a public value where the object or value needed isnt set/referenced

slender nymph
digital warren
#

,_,

#

damn my unity crashed!

#

wait

slender nymph
#

how to correctly share !code 👇

eternal falconBOT
digital warren
#

right?

slender nymph
#

you need to read the bot's instructions for sharing code, yes

digital warren
#

ohhh this better yo

hallow acorn
slender nymph
hallow acorn
digital warren
#

and its not a (GameObject)

#

game works but when i log in using this pakage photon give me datamanger error and these creepy things ,_,

hallow acorn
#

public class CanonMain : MonoBehaviour
{
    public GameObject projectilePrefab;
    public float projectileSpeed;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) {
            LaunchPrefab();
        }
    }

    void LaunchPrefab() {
        Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.rotation);
        projectilePrefab.GetComponent<Rigidbody>().AddForce(transform.forward * projectileSpeed);
    }
}```
could somebody tell me why my addforce is changing litteraly nothing at all?
slender nymph
#

you probably want to use ForceMode.Impulse for a one-off force

#

also you're adding force to the prefab not the instantiated object

hallow acorn
digital warren
#

or what ,_,

#

man iam noob lol

slender nymph
hallow acorn
slender nymph
#

obviously yes since that is where your error is

digital warren
#

alright wait

slender nymph
#

i have been

hallow acorn
slender nymph
#

Instantiate returns the instantiated object

hallow acorn
#

im a complete noob wdym xD

slender nymph
#

there are beginner c# courses pinned in this channel if you do not know how to use the return value of a method

digital warren
#

@slender nymphstupid Q lol

celest holly
#

how is this not moving my bullet in the position of my mouse? is just going anywhere

digital warren
#

how can i share the code from there again 🙂

slender nymph
#

you save it and share the link

hallow acorn
slender nymph
eternal falconBOT
digital warren
#

like that?

#

ohhh noice it worked

slender nymph
#

since the error is on line 239 that means it is if (data.ContainsKey(key))
there are only two objects on this line that could be null data and key. you need to determine which is null and then look at the stack trace to see where you are calling this method from to determine why it is null

slender nymph
#

also why do you have a folder named Assembly-CSharp? is this a decompiled project?

digital warren
#

i know break rules

#

lol

slender nymph
#

it is against the rules to assist with stuff like that

digital warren
#

i know

digital warren
#

iam crying now ,_,

slender nymph
#

yeah i'm blocking you now. don't need the spam or the willful rule breaking 🤷‍♂️

summer stump
digital warren
#

like how to add

#

and these things ,_,

#

alright fine i will delete this project

#

gg to me ._.

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

digital warren
#

fine fine i will learn yo

#

,_,

proven mirage
#

hey guys im currently in a game jam and trying to make a game about snakes and im making a snake battle royale and im trying to get a snake where it follows the mouse like slither.io and i have that its just i need help with segment rotation so like every sement shoul lepr its rotation to the next one do you understand becuase this is what i have now

#
public class SnakeMovement : MonoBehaviour
{
    public float MovementSpeed;
    Vector2 MousePos;
    public List<Transform> SnakeSegment;
   
    public float SegRotTime;
    void Start()
    {
        foreach (Transform t in transform.GetComponentsInChildren<Transform>())
        {
            if(t.gameObject != this.gameObject)
            {
                SnakeSegment.Add(t);

            }
        }

        
        
    }

    // Update is called once per frame
    void Update()
    {
        SnakeFollowMouse();


    }


    void SnakeFollowMouse()
    {
       
        MousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        transform.position = Vector3.MoveTowards(transform.position, MousePos, MovementSpeed * Time.deltaTime);

        Vector3 direction = Input.mousePosition;
        direction.z = -Camera.main.transform.position.z;
        direction = Camera.main.ScreenToWorldPoint(direction) - transform.position;
        transform.rotation = Quaternion.LookRotation(Vector3.forward, direction);
    }

  
}```
#

im moving the snake as a whole right now but i want the indual senments follow one another smoothly so i was just wondering how can i accomplish this?

slender nymph
#

you would want to separate the objects, child objects immediately follow the position and rotation of their parent, so if you rotate the parent, then the children get rotated along with it

#

I would personally have some component that controls individual segments, have that component get a reference to the segment in front of it so it can follow at the desired offset and smoothly rotate to face it

proven mirage
#

oh okay

#

@slender nymph

#

like this?

#

bc if idont parent them then its gonna be very disorganized

slender nymph
#

i feel like you didn't read any of what i just told you

proven mirage
#

i read it

#

you said not parent them

slender nymph
#

so if that is the only thing you took away from what i said, why would you think i would say yes to your "like this?" question when you are doing exactly what i said you shouldn't be doing

proven mirage
#

oh my

#

my bad

#

my heads in the gutters today

slender nymph
#

you didn't even change anything. that hierarchy structure is exactly like it was in the first screenshot

proven mirage
#

eyah your right

#

wait but box friend

#

how would i spawn snake object then?

#

like as whole because if i want to make a prefab of a snake and its not a parent then its gonna be alot harder to spawn them

slender nymph
#

spawn snake root object. have that object spawn its individual segments in a loop so that they are not directly connected

proven mirage
#

would there performance issues if i were to spawn 100 snakes?

slender nymph
#

it would be exactly the same "performance issues" if they were 100 snakes with the segments as children since it's still the same number of objects doing the same things

proven mirage
#

ok

slender nymph
#

if you make them child objects, then each time you rotate any of the parent objects you will then need to rotate the children in the opposite direction in order to ensure that they aren't all rotating exactly the same which i believe is your current issue

proven mirage
#

oyh

#

ok thats sounds tricker

#

i dont have that typoe of time imma just go with the first method

#

@slender nymph

#

ok so i did through script now justa quick question can i accomplsiht he same thing unsing joints and would that be easier or should i just it through code?

#

what imean is the rotation part

slender nymph
#

that's going to require multiple rigidbodies. do you need physics for this?

proven mirage
#

so i dont think so

#

bc its a top down game

#

so theres no ground

#

so no id think so

#

i dont think so

proven mirage
#

what would you reccomend in this case

slender nymph
#

i already told you what i recommended you do

#

if you want to use joints, go for it. but each segment will need its own dynamic rigidbody

#

if you go that route, you can switch back to making the segments children objects since rigidbodies will move on their own (provided you aren't constraining their movement)

#

and also remember that physics is not just gravity.

proven mirage
#

ill try the first method

modern root
#

Hello!

#

I need help with the old Input Manager (not the new one)

#

It seems to have support for around 30 axis of joystick input. I'm trying to understand what all axis are for past the first few ones. 2 of them for a stick, 2 of them for the other stick, 2 of them for dpad, then there's some of them mapped to the triggers.
Are there axis dedicated to the face buttons too?

#

(Yes I know you can use button for face buttons, but I'm in a situation where this is not possible)

#

I can't find reference to which actual input each of those axes are mapped to and reference I find online is lackluster or contradictory. I also do not see them documented!

desert temple
#

Hello. I'm a rank beginner, and I'm currently trying to make a pause menu. I've followed a tutorial, but I'm getting this error, and I'm not entirely sure what's wrong with my script, beyond what it is telling me.

slender nymph
#

configure your !IDE so you don't make silly spelling mistakes like that

eternal falconBOT
summer stump
proven mirage
#

@slender nymph i have thgis code to follow towards the mouse pos but for some reason my z position keeps lepring to negitve 10 causing my snake to go off screen

slender nymph
#

or just set MousePos's Z coordinate to 0 after the ScreenToWorldPoint call

desert temple
modern root
#

Should I be using this dropdown menu if I already specified the joystick index in "Positive Button" ?

summer stump
#

I mean... you got an error. Errors do not lie

#

Also, it is clearly capitalized incorrectly

desert temple
#

I mean, I know that, logically. But which is capitalized wrong?

modern root
#

Install visual studio tools for unity if you're using Visual Studio this will avoid this kind of headache for you

summer stump
#

NO property is lowercase for the second word

summer stump
#

Again, there is NO property that has a lowercase second word

#

There is some inconsistency in the FIRST word. And argument about which is right. But across the board in unity, the second word is capitalized

#

Do what you were told above and configure your ide, it will underline errors and even tell you how to fix them most of the time. It is VERY helpful

modern root
#

I have an issue where either my input is detected on all controllers, or none at all

#

I don't know how to do for my virtual axis to be detected only for joystick 1 or joystick 2

desert temple
#

Ah, it was timeScale, not timescale. Now I'm running into an issue where the pause menu is just stuck up, though.

modern root
#

and I have to say the documentation about this is really confusing. Most of the forum posts I find are about the new input system and posts about the old ones are seemingly going missing

#

But I figure out there must still be some people around who have experience with the old system to help me? 🙂

summer stump
wanton kraken
#

how can i have rounded corners on a box collider/tilemap colldier? these sharp corners are giving me lots of trouble, that would likely solve it

modern root
#

Should I go in another channel maybe?

summer stump
modern root
#

I thought this would be a beginner question but maybe I misjudged and it's not

wanton kraken
summer stump
desert temple
summer stump
# wanton kraken i see. so what to do?

Maybe a squashed capsule? Or a custom shape.

May be an xy problem though. Is the issue that the player is catching on the map? Maybe make thr PLAYER a capsule

wanton kraken
#

i could do that, but the player is rectangular so the sides would just clip through the walls

summer stump
summer stump
wanton kraken
#

the player is a tank, which is rectangular. a capsule collider can't fully cover said rectangle without being larger then it

desert temple
summer stump
static bay
#

Like the same object that has the component script?

proven mirage
#

hey guys how can i keep objects apart in unity 2d by a certain ditance at all times?

#

bc right now i have that code in the if statement

#

except the objects still move closer to each other bc they have to hit that limit before stopping to moe i was just wondering is there a way to keep a constant distance between objects?

cosmic dagger
# proven mirage

you check if the distance is greater, then it moves closer. you don't check if it's too close to then stop . . .

#

you should do the opposite. if the distance is too close, move away. once it's at the distance, it won't move any more . . .

desert temple
static bay
upbeat skiff
#

so im trying to make a script that collects stuff when the player touches them

#

but i get these errors

frosty hound
#

The variable score of iron has not been assigned. You probably want to assign something to score.

cosmic dagger
upbeat skiff
#

ohh

#

thank you

desert temple
static bay
#

is this always empty?

cosmic dagger
upbeat skiff
#

yeah well i set the score variable but still does error

cosmic dagger
cosmic dagger
icy sluice
#

hello, im doing bullet physics and im kinda stuck, so here is a question:
how would you make ricoshet/bounce check for a bulet at angle (please not an angle threshold)

upbeat skiff
#

the other scripts were from the asset itself

proven mirage
static bay
cosmic dagger
upbeat skiff
#

oh yes there is

#

let me check them

light arrow
#

Everything works the attack, but the player does not move. The animation controller is showing that it is receiving the input but the player just doesn’t move from its spot. The animation works just my player won’t move. Please help

eternal falconBOT
static bay
rich adder
static bay
rich adder
#

but yeah we don't need code as ss lol

icy sluice
#

idk how i could make a toggle for it that isnt a angle threshold

wintry quarry
icy sluice
queen adder
#

Square map: when you reach edges, you switch map, stucked to deciding whether we'll use colliders or constant position check per step, any insights?

winged stone
#

hello guys, how can i fix this?

cosmic dagger
#

the method does not take 3 arguments. so don't give it 3 arguments . . .

#

check the unity docs for the method to see the arguments and/or overload methods . . .

velvet kernel
#

i dont know what im doing, anyone got any tutorials?

#

.lua was easier

#

everything is so complicated

queen adder
#

google : Unity how to _

velvet kernel
#

if i want to learn how to code do i start aiming for something i want to code or just start coding the basics to figure out what im doing

slender nymph
#

you should start with beginner courses that go over the fundamentals, like the courses pinned in this channel

velvet kernel
#

thank you

meager gust
# winged stone

you might want to fix your IDE so you have proper syntax highlighting

#

its a lot easier to program when you can see visual patterns in the code itself

wintry quarry
light arrow
#

How do I do an if statement for if I click my mouse

icy sluice
wintry quarry
velvet kernel
#

i am bamboozled

#

nothing is making sense

meager gust
#

@velvet kernelthere's a lot of overlap between regular C# and unity C#. Just start with the basics like a console application

#

you shouldn't expect yourself to become a pro right off the bat

velvet kernel
#

yea i know i know

#

but god damn

meager gust
#

you'll also need a little bit of knowledge on vector math if you want to do anything interesting with 3d

#

I'm sure you know this though

velvet kernel
#

is modding easier then creating?

#

might start with that if it is

meager gust
#

modding depends on the game, really.

velvet kernel
#

lets say a car game

meager gust
#

entirely subjective

velvet kernel
#

ik one that allows modding thats unity

meager gust
#

just don't give up so easily. copy and paste some examples and rip them apart

#

I promise it's not as difficult as it all seems.

velvet kernel
#

for now i only know how to open up the coding software

#

from then on its a big step thats twice as big as me

#

if yk what i mean

light arrow
#

Is there a more efficient way to do this

meager gust
#

just take it one step at a time. there's hundreds of tutorials

wintry quarry
velvet kernel
#

lets say i want to start with modding how do i get the code i want to mod

meager gust
verbal dome
wintry quarry
meager gust
#

which will probably be in his modding documentation

#

which you'll need to read

slender nymph
meager gust
#

yeah, there's no way around coding. if you're going to mod, it's going to be code heavy.

velvet kernel
slender nymph
#

i'm being genuinely serious. if you want to develop a game or mod you need to learn to code

velvet kernel
#

for me learning from a tutorial is much harder then someone explaining it to me

#

what do i even start with

meager gust
#

text based tutorials / documentation

velvet kernel
#

"static void Main(string[] args)" what does static and void mean

meager gust
#

you can google that, and you'll get 100 answers

#

there's also a dedicated C# discord to help you with the absolute basics

summer stump
meager gust
#

the entry point of a barebones application will generally be static 🙂

velvet kernel
#

whys code gotta be so complicated

meager gust
#

c# is very straightforward compared to lower level languages.

#

people in the 90's had it much worse

velvet kernel
#

i need a online course where i can learn

summer stump
velvet kernel
#

where i can ask questions and someone answers 😭

meager gust
#

my man, just copy and paste the examples on w3schools, read the 3 lines of text explaining it

#

and just play around with it

#

you've got to be interested to learn.

summer stump
eternal falconBOT
velvet kernel
#

alr well

#

ill take your guys advice

#

but i dont think my brain is able to handle the amount of information coming in and is just turning off 3 seconds into watching a tutorial video

#

ill try tmr

#

im too tired for this rn

summer stump
patent rover
#

also i have to use unity 2022.3.9

summer stump
teal viper
ivory bobcat
#

They probably want to move the parent but have not provided us enough code to differentiate what was instantiated

patent rover
#

Im sorry for struggle english ,im studying it now
I want to move objects generated by "Instantiate" thing

ivory bobcat
#
var instance = Instantiate(...);
Move(instance);```
#

It would depend on your movement system but basically, cache the new instance and move those.

patent rover
ivory bobcat
patent rover
upbeat skiff
#

can someone help me create a script for touchscreen input?

slender nymph
#

if you need help with something specific about that, then Don't Ask To Ask
if you are asking for someone to actually do the work for you then 👇 !collab

eternal falconBOT
rocky canyon
#

use the new input system, create an action map for Touch Input, Generate the C# Class, then Get the input using ReadValue

slender nymph
#

this is a code channel

wanton kraken
#

my mistake

magic panther
#

can I make my collider a detection only one? As in nothing with a collider will interact with it physically, but I want to do something every frame a specific object (which has a boxcollider2d as well) is within this box. Is that possible?

slender nymph
#

make it a trigger. but is there a reason it needs to be an actual collider and not perhaps a physics query like an OverlapBox?

slender nymph
#

start by learning the fundamentals. there are some excellent beginner courses pinned in this channel

#

the fundamentals of code because this is a code channel

topaz mortar
#

I have an Item script/class
At the moment I have 3 major item types, probably more coming in the future: equipment, scrolls, spells
Equipment is then further divided into: weapons and armor, which can each be divided further as well, like 1h weapon, 2h weapon, helm, body, boots, ...

For now this is all in my Item class, but I've realized I need to rework this now to add spells to my game, they will have a lot of different fields and won't use most of the fields the current items use. (Is field the correct term? Or attributes?)

So I'm planning to add 3 child classes for Item: Equipment, Scroll, Spell
Not sure if I should further divide equipment? How do I determine that?

willow scroll
lusty parcel
#

Hello, I am currently trying to write a custom component script for a unity, this is my first time attempting a custom script of this sort. My question about this script does not have anything to do with the game it is for so hopefully i can get help here.

I am currently having the component create a meshcollider component on whatever gameobject it is assigned to, i have gotten this part working, but i am now trying to have it automatically assign that meshcollider component to its own meshcollider slot "_modifierArea" as well as have it make that mesh collider both convex and a trigger.

I believe my current problem is that i have the code that does that second part in the Start() void, which only happens when the game is running, and I would instead like it to run whenever the component is added in unities editor. I am unsure how to do this though. someone has suggested i try putting that code in the constructor itself? I am not completely sure which part of this is the constructor, or how i would implement that. As when i try to copy the code out of the void Start(), unity throws errors saying that methods are not allowed in a namespace.

using System;
using UnityEngine;
using Utility;
using Game.Units;
using Ships;

// PlayerScript requires the GameObject to have a Collider component
[RequireComponent(typeof(MeshCollider))]
public class MapModifierZone : MonoBehaviour, IModifierSource
{
    [Tooltip("The trigger volume used to define the area in which the modifier(s) is/are applied")]
    [SerializeField]
    private Collider _modifierArea;
    [Tooltip("This name is used to differentiate from other sources of modifiers (e.g. Energy Regulators, Ammo Elevators, Drives) Make it unique from other modifier appliers, but the same across all zones of the same type (so the modifier doesnt stack to maximum unintentionally)")]
    [SerializeField]
    private string _zoneSourceName;

    string IModifierSource.SourceName => _zoneSourceName;

    // Start is called before the first frame update
    void Start()
    {
        // Ensure the MeshCollider is set as convex and is a trigger volume
        MeshCollider modifierAreaMesh = GetComponent<MeshCollider>();
        if (modifierAreaMesh != null)
        {
            modifierAreaMesh.convex = true;
            modifierAreaMesh.isTrigger = true;
        }
        _modifierArea = modifierAreaMesh;
    }

    // Update is called once per frame
    void Update()
    {

    }
}
#

nvm

#

i got it

#

that always happens right as you ask for help xD

twin pivot
#

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

public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IDropHandler
{
public GameObject Hand;
GameObject Hand = GameObject.Find("Hand");
public GameObject Table;
GameObject Table = GameObject.Find("Table");

eternal falconBOT
teal viper
twin pivot
#

how do I fix this?

stoic phoenix
#

Hi all, is there a way to enable word wrap for the Unity console?

teal viper
teal viper
twin pivot
#

but if I dont add that it says table is not defined

#

trying to get this to work

teal viper
twin pivot
#

orginParent is a variable i added before

teal viper
#

I suggest you follow the beginner pathways on unity !learn and maybe learn the C# basics separately as well.

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

twin pivot
#

but why wouldnt the else if portion work

teal viper
twin pivot
teal viper
#

I thought I already explained that this is invalid. You can't have 2 variables with the same name

twin pivot
#

i dont know where im making 2 variables though

teal viper
#

Here:

    public GameObject Hand;
    GameObject Hand = GameObject.Find("Hand");
    public GameObject Table;
    GameObject Table = GameObject.Find("Table");
stoic phoenix
#

Do you have a typo with "orginParent"?

twin pivot
teal viper
twin pivot
#

isnt this making a variable called Hand

#

and then putting the Hand gameobject in it

stoic phoenix
#

I don't think GameObjects are considered a variable in Unity, right?

stoic phoenix
#

Variables are usually assigned to datatypes, like string, int, char, float

slender nymph
teal viper
twin pivot
#

oh

slender nymph
teal viper
random dove
#

please fix my prob

twin pivot
#

I deleted these

public GameObject Hand;
public GameObject Table;

teal viper
#

Again, I suggest you stop right there and go learn the basics properly

twin pivot
#

i im trying to compare a string and a gameobject

teal viper
twin pivot
teal viper
random dove
teal viper
twin pivot
#

i dont know how to change it to work

random dove
#

i came here for hlep

teal viper
#

If you have a question just ask it, and someone might be able to help

random dove
teal viper
slender nymph
random dove
twin pivot
random dove
teal viper
slender nymph
twin pivot
#

the problem i'm having with this approach is that im getting ahead of myself and going back to change things that ive already written

#

with newer concepts i dont understand as much

teal viper
twin pivot
#

well i understand most of what i've written

#

the top part that wasnt working was written by my friend as a suggestion

teal viper
#

That's why I suggested unity !learn and/or go over the C# manual/beginner courses.

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

twin pivot
#

i'll do it after i fix this bug

slender nymph
twin pivot
teal viper
twin pivot
#

damn alr

teal viper
# twin pivot damn alr

If you're learning as you're going, you should be able to go to the C# documentation and read on the relevant topics, namely, types, and variable comparison.

#

I highly doubt you'll be able to understand it without learning properly some even more basic things though

twin pivot
#

main reason why i've jumped into things is because i learned python and i hoped it would be similar enough to be a crutch

#

obviously it was not

dreamy dune
#

hey,
i have a little problem so i have a chest where i want to interact with but the interaction system is based of mesh collider so the problem is that i have two seperate colliders in the chest one for the top and one for the bottom my question is is it possible to sort of combine two collider into one?

teal viper
slender nymph
twin pivot
#

also doesnt help that python is pretty far from c#

teal viper
#

Yep

copper horizon
#

guys need help

#

how to add dont show again tick mark on panel??

teal viper
copper horizon
#

ok thanks buddy

lusty parcel
#

Ok now another question, the goal of this script is to have a zone on a map that applies an effect whenever a ship/player enters the zone. In particular i am wondering if having the component to define the zone be a trigger mesh collider will be an issue?

#

players need to move in and out of the zone, will a trigger mesh collider block this?

#

ok it seems that triggers are correct

dreamy dune
# slender nymph you could give the root object a rigidbody, that would combine both of the mesh ...

if (Physics.Raycast(ray, out RaycastHit hit, interactionDistance))
{
if (hit.collider.gameObject.layer == 6 && (currentInteractable == null || hit.collider.gameObject.GetInstanceID() != currentInteractable.gameObject.GetInstanceID()))
{
hit.collider.TryGetComponent(out currentInteractable);

            if (currentInteractable)
            {
                currentInteractable.OnFocus();
            }
        }
    }
    else if (currentInteractable)
    {
        currentInteractable.OnLoseFocus();
        currentInteractable = null;
    }

so here i need to check rigidbody instead

ivory bobcat
#

Don't spam random people. Provide the necessary data by following the guide on how to ask questions #854851968446365696

eternal falconBOT
modest dust
#

If someone knows how to help, they will

opaque scroll
#

hello

#

can i ask coding question hele?

#

here?*

fickle plume
opaque scroll
#

okay

#

ive got this script and the problem is
the object deletes itself before particles have chance to play
i thought maybe there is a way to make it "sleep" one second before it deletes itself

#

lemme post a screenshot

#

I tried doing it using Invoke ("DestroyDelay, 1); but it just doesnt work

#

maybe u have some suggestion how could i do it so it waits 1 second before executing the Destroy line

frank zodiac
#

so i have this block of code that successfully debugs but it doesnt set the panel inactive for some reason: ```
public void ClosePanel()
{
panel.SetActive(false);
Debug.Log("fgdfgfd");
}

i have everything set in the inspector it just wont work
opaque scroll
#

how can i do that

teal viper
opaque scroll
#

okay thank you!

teal viper
frank zodiac
#

it prints the correct name

#

it opens successfully but never closes when i hit the button

teal viper
# frank zodiac yeah it is 100%

Assuming it's really the correct object, you must be enabling it somewhere after that.
Maybe add a log in that object's OnEnable/Disable to confirm that and see where it's enabled from.

frank zodiac
#

but disabling it in another script

teal viper
#

Doesn't matter.

cobalt sentinel
#

What's wrong with this line?

teal viper
teal viper
cobalt sentinel
frank zodiac
teal viper
cobalt sentinel
teal viper
frank zodiac
#

if its just 1 then its fine

teal viper
frank zodiac
cobalt sentinel
teal viper
frank zodiac
#

also dont use Vector3 use Vector2 since your game is in 2D

#

doesnt really matter but its better for consistency

teal viper
frank zodiac
full kite
#
    {
        GameObject myGameObject2 = new GameObject("Lvl" + level);
        ren = myGameObject2.AddComponent<SpriteRenderer>();
        ren.sprite = CamilaLvl2;
        bc2d = myGameObject2.AddComponent<BoxCollider2D>();
        rb2d = myGameObject2.AddComponent<Rigidbody2D>();

        rb2d.gravityScale = 0;
        bc2d.isTrigger = true;
    }
    
    private void OnTriggerStay2D (Collider2D collision)
    {
        string thisGameobjectName;
        string collisionGameobjectName;

        thisGameobjectName = gameObject.name;
        collisionGameobjectName = collision.gameObject.name;

        if (mouseButtonReleased && thisGameobjectName == "Lvl1" && collisionGameobjectName == "Lvl1")
        {
            mouseButtonReleased = false;
            Create(2);  
            Destroy(gameObject);
            Destroy(collision.gameObject);     
        }
    }```

Hello guys! I got this script here. Basically when 2 gameobjects collide, i want to destroy them and spawn a new one. A new one does spawn, got all the components right, but the sprite isnt assigning to it. Does anybody has an idea?
teal viper
full kite
teal viper
full kite
#

But this is the thing here that I completly dont understand

teal viper
# full kite

Maybe instantiate a prefab with all the refrences assigned instead of creating a new gameobject?

full kite
teal viper
#

A prefab is a prefab. When you instantiate it, you create a copy of the prefab in your scene. With all it's references intact.

frank zodiac
#

what are some use cases in which you might use the interface keyword?

full kite
#

Let me clarify a bit. So, by pressing a button, I spawn a gameobject. The image of the gameobject is being taken from where I stored the script (in Canvas). I added as a component my script, cause in the same script is a movement feature and I need it for my gameobjects. I added that script to the gameobjects and all the references are gone. How can I assign them back? Cause if in run time, if I assign them to both of my gameobjects, when colliding them, a new gameobject spawns that HAS the sprite

teal viper
frank zodiac
#

i dont get it

teal viper
frank zodiac
#

i like to think of interface and abstract classes as c++ header files

teal viper
full kite
frank zodiac
#

well what are the use cases for them? they seem pretty useless

teal viper
#

Not explicitly, but many people implement them as such.

teal viper
full kite
teal viper
full kite
#

how can I drag it, if I dont have it yet?

#

nvm, I can drag it during runtime and it stays

frank zodiac
teal viper
full kite
#

Why do I cant assign some of them

#

like gameobjects

#

I cant assign those

teal viper
teal viper
teal viper
frank zodiac
full kite
#

Ok so

#

Instead of spawning a gameobject

#

i spawn this prefab

#

that alr has all the references available

#

like a prefab with all the inspector made alr

teal viper
teal viper
# full kite

This is pretty much self explanatory. You're passing a null into Instantiate

teal viper
#

Exactly what I said.

#

You know what a null is?

full kite
#

like not assigned

#

something that not exist

teal viper
#

Yes

full kite
#

but its assigned

teal viper
#

Well, the error says it's not

#

Debug what you're passing into the Instantiate method.

full kite
#

So I added this

#
public GameObject Camila2;
GameObject instance = Instantiate(Camila2, new Vector3(1,1,), Quaternion.identity);
#

And I assigned it with the prefab that I dragged

#

in the assets

teal viper
#

Debug it

#

Here's a pro tip: don't just assume, always confirm.

full kite
#

its the same problem

#

the exact same problem

#

The prefab its not assigned in the inspector cause that gameobject it was created inside of the script and the inspector is empty

teal viper
full kite
#

wait a bit

#

ill try to debug

pliant sleet
#

can someone explain to me (in the easiest way possible) what a static variable is ?

languid spire
pliant sleet
#

oh so when you need to access that variable you need to use the specific class, without even declaring it in another script ?

languid spire
#

because of this there can only be one value for a static variable regardless of the number of instances that the class may have

pliant sleet
#

i am trying to learn data persistence between scenes and i want to fully understand it

burnt vapor
#

Static variables are not a good way to persist your data. They are just easy to access because they don't need an instance

languid spire
#

static varialbe values will persist

burnt vapor
#

If you want to persist data, consider storing gameobjects using Dont Destroy on Load, or create a separate transient scene that always exists

#

Using static variables when their gameobject has already been destroyed can lead to messy code

pliant sleet
#

It is a tutorial from unitylearn

burnt vapor
#

And on the topic of static and persisting data, your gameobject could be turned into a singleton if you are storing data in it. The singleton pattern is perhaps something you could take a look at how they work.

burnt vapor
pliant sleet
#

that's the script from the gameobject that I want to save between scenes

burnt vapor
#

Alright, all you need to do is call Dont Destroy on Load on it

#

This creates a new scene managed by Unity where all objects must exist that don't get destroyed

pliant sleet
#

and the "this" variable is basically what am i assigning the script to ?

burnt vapor
#

this means the calling class, so your MainManager instance

pliant sleet
#

alright

burnt vapor
#

You assign it to the Instance field, which is static so you can easily get this instance again

pliant sleet
#

yeah

burnt vapor
#

Your code in Awake basically checks for an existing instance in Instance, and if so it destroys the second instance of MainManager, since we already have one

#

Sorry, I misread your code. You already call Dont Destroy on Load

#

You don't need to do anything in that case, this object already persists

pliant sleet
pliant sleet
burnt vapor
#

So what do you want to know?

pliant sleet
#

so the "DontDestroyOnLoad()" method creates that separate scene that saves my gameobject, right ?

burnt vapor
#

Yes, if you start up your game and make a manager instance you can see the scene in your hierarchy

pliant sleet
#

Yes

burnt vapor
#

You can also make a second transient scene and do it yourself

#

This is mostly useful if the first scene varies or you don't want to be bound to one

pliant sleet
#

I will do so

outer wigeon
#

This line of code loads Json files from a subfolder of my Resources folder. It works in the editor but I'm not able to retrieve them in WebGL builds. Do I need to switch to a StreamingAssets approach to access json files in this way in WebGL?

currentNode.nextDialogueJsonFile = Resources.Load<TextAsset>(currentNode.nextDialogueJson.Replace("Assets/Resources/", "").Replace(".json", ""));
languid spire
#

If that works in Editor it should work in WebGL. What errors are you getting in the web developer console of your browser?

outer wigeon
tidal valve
#

so i am trying to make a movement system, and my gravity isn't working, it keeps adding down force with out resetting it/stopping. pls help am very stupid (its also not giving any errors its just not working as its supossed to)

    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if(isGrounded && velocity.y < 0)
        {
            velocity.y = -2.0f;
        }

        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;
        controller.Move(move * speed * Time.deltaTime);

        velocity.y -= gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
}```
languid spire
tidal valve
#

is supossed

#

tio

#

reset

#

velocity

languid spire
#

write in full sentences

tidal valve
# languid spire write in full sentences

sorry, it was bc i pressed enter without holding shift for new line.
but basicly if(isGrounded && velocity.y < 0) { velocity.y = -2.0f; }
is my attempt at reset the velocity, and velocity.y -= gravity * Time.deltaTime; is supposed to give you more velocity as ur falling to make it more realistic

languid spire
#

so you logic should be

if grounded
   velocity.y = 0
else
   velocity.y = apply gravity
tidal valve
#

i think this will work lemme try it

#

i might be wrong

late burrow
#

so before for moving object along linerenderer i was calculating length of each segment and adding them all together, but when i will start generating curves it may be getting laggy jumping through all segments every frame, i thought to instead make very large array of positions where distance between each of them is exactly same, so then i can get position directly with [i] is that good or bad

tidal valve
#

but i just tried that, it didnt work, its still just added velocity

languid spire
fickle plume
tidal valve
#

i dont think i am understanding what ur saying

languid spire
late burrow
frosty hound
languid spire
late burrow
tidal valve
late burrow
#

so i dont need care about poitns only length of array

frosty hound
#

Sounds silly, but it's you so doesn't surprise me. Good luck.

languid spire
tidal valve
languid spire
#

no, you need both

tidal valve
languid spire
#

OMG

#

I give up

tidal valve
languid spire
tidal valve
languid spire
#

and why would you use deltatime twice

tidal valve
tidal valve
sage mirage
#

Hello, guys! Could you please tell me the most efficient and simple way to create stairs functionality for my player in a first person horror game? I want to learn the methodology of that functionality.

void raptor
#

I was working on animations when all of sudden the animator blocks disappeared and it starts giving me this bug

#

why?

tidal valve
sage mirage
#

I think I have to make that thing with raycast right?

#

stepLower and stepUpper

#

That's all very confusing really

tidal valve
sage mirage
sage mirage
void raptor
swift crag
#

it looks like something went wrong in the graph view

void raptor
#

Did

swift crag
#

And the issue persists?

void raptor
#

No, it worked