#💻┃code-beginner

1 messages · Page 145 of 1

dusky tusk
#

ok im using rigid body now but it cant move on the ground now

#

like there is a velocity on the x axis but its like 0.6, and i cant seem to see the body moving

#

it moves fine when im not on the ground though

teal viper
#

Might want to provide more details. Start from a video of the issue.

#

As well as the relevant code.

dusky tusk
#

i cant record but i can show you my code

#

i might just rewrite my code lol

#

are there any resources about platformer movements but instead of jumping, its jetpacks ?

queen adder
warm sleet
#

Hello, I need some advice, I´m doing a 2D game and Im not sure if I should create the objects when I need them or should I create them when loading the game, and later on set them active or not, for example, I have an enemy pool where I have all the enemies but I don´t know if that would work for when the turrets shoot , does the performance of the game may variate if I create them or if I just set them acrive or not?

fossil drum
warm sleet
#

ty blushie

mellow elbow
#

Is it possible for me to loop a coroutine until a certain condition has been met?

keen dew
#

Yes, that is the most common use for coroutines

mellow elbow
#

ohh lol

spiral rain
#

Anyone

modest dust
spiral rain
#

I’ll repost

modest dust
#

You didn't really describe what your issue even is

mellow elbow
#

what do you need help with

odd mason
#

is there a better way to check if hte player is on ground reliably? im using this and idk if i just suck at values or smthn but its like not working properly, what is ground is a layer mask btw

spiral rain
swift crag
swift crag
spiral rain
swift crag
#

This will only detect 3D colliders

odd mason
#

3d physics

swift crag
#

I would raise the raycast's origin a bit

#

I believe raycasts ignore colliders that they start inside of

odd mason
#

k, ill try that out, thanks

neon marsh
#

hi i have a question. Why is my NavMeshSurface not working?

#

ive been trying to do Monster AI lately

swift crag
#

what does "not working" mean?

neon marsh
#

idk

swift crag
#

then how am I supposed to help you?

neon marsh
#

not showing this like

#

blue

#

area

#

but yea i dont know how to set it up

swift crag
#

show me the inspector for your NavMeshSurface component

neon marsh
#

yea

swift crag
#

Also unfold the "Object Collection" and "Advanced" sections

#

i forgot those were collapsed by default

neon marsh
#

yea

odd mason
#

thanks for the help! works perfect now

mellow elbow
#

How do I loop a coroutine until a certain condition is met

mellow elbow
#

I know it has something to do with that, but I dont know where to place the while loop
and should the while loop be activating the coroutine or the code while it is inside the coroutine

swift crag
#

if you want to make a coroutine repeatedly do something until a condition is met, put a while loop in the coroutine

#

If you want to run the loop once per frame, then you must yield return null; somewhere in the loop

rich adder
fossil drum
swift crag
#

WaitUntil is ideal if you just want to...wait, yeah

mellow elbow
rich adder
mellow elbow
#

I was already doing this but it bugged out but it fixed itself for some reason

#

Thanks for the help

swift crag
#

what "bugged out"?

mellow elbow
#

The loop ended and the coroutine just ended itself even though the condition wasnt met

swift crag
#

while terminates once the expression evaluates to false

mellow elbow
#

Yes

languid spire
mellow elbow
#

The debug said it was done (Which happens when the while loop is finished) so i'm not sure

#

ill just see if it still happens

#

I seemed to have fixed it

#

Oh wait

#

I just recalled

#

ok I know what's causing the problem

pallid verge
#

how can i find the fuelbar gameobject which has a tag FuelBar?

rich adder
#

so how do we get a component from gameobject ?

pallid verge
#

i think i know

#

wait lemme try rq

#

btw the FuelBar variable is a script right

#

ik its my code but im not really sure

#

or a class rather

rich adder
#

its FuelBar type

#

you need to GetComponent from the returned GameObject

pallid verge
rich adder
#

sure u can make it two lines

pallid verge
#

are u happy now

rich adder
pallid verge
#

alright ty

rich adder
#

FindObjectOfType can prob be used since it finds the component directly

mellow elbow
#

the condition is if its less than 6

polar acorn
# pallid verge

Just to make sure: is there a reason you cannot just make fuelBar serialized or public and just drag the object in

pallid verge
rich adder
# pallid verge instead of what

instead FindGameObjectWithTag
idk which one is faster, but I dont use not to use tags so don't take my word on it 🙂 tag should be fine though

polar acorn
#

A find in start for a prefab is fine

pallid verge
#

i mean its not like im putting hundreds of them but i just wanna have the smallest amount of things to worry about

rich adder
#

I use components directly

#

its like a tag but better since you're not bound to strings 🙂

polar acorn
#

If there's only one FuelBar object in the scene though you should use FindObjectOfType instead of getting the object and getcomponent, it's slightly faster

pallid verge
#

yeah there is

polar acorn
# pallid verge how dont u use tags

All Finds can be avoided with proper planning and dependency passing. The object spawning the prefab could set the variable on the instance after spawning one, for example.

pallid verge
#

it works now thank you

rich adder
#

sweet

pallid verge
#

i have another question, can i use a foreach loop in unity?

rich adder
#

ofc lol

pallid verge
#

i was asking cuz i tried to use a while loop and unity crashed

rich adder
#

the only thing unity can't do is run .NET7+ functions

rich adder
#

regardless

pallid verge
#

oh alright

rich adder
pallid verge
#

i know what infinite loops are lol

rich adder
#

just checking

mellow elbow
#

If a Coroutine is Started can it be started again mid coroutine?

rich adder
#

each time you StartCoroutine you create a new one

mellow elbow
#

Im asking so incase the player triggers a coroutine that they cant just spam it

mellow elbow
#

so I false it at the start and true it at the end?

rich adder
mellow elbow
#

ah

#

Makes sense

rich adder
#
 void method()
    {
        if (running) return;
        StartCoroutine(SomeRoutine());
    }
    IEnumerator SomeRoutine()
    {
        running = true;
        while (stuff)
        {
            yield return null;
        }
        running = false;
    }```
fossil drum
#

I honestly don't understand why you don't use WaitUntil, it can't give you an endless loop, it's easier to read, it's less amount of code.

dim halo
#

how can I create a parent object for both text and button at the same time

#

I would appreciate any kind of help

#

I'm beginner

rich adder
#

what are you trying to do with that

dim halo
#

here is the thing, in the tutorial that I'm watching the guy has a parent object called ``game over screen` for both the text and button. Unfortunately, for some reasons that I dont remember, I dont have that one, now im trying to add it

dim halo
#

but I want it to be parent object

rich adder
rich adder
dim halo
#

so i should first make a child object under the canvas

rich adder
#

you can also right click one of them and Create empty parent

mellow elbow
dim halo
#

and make the text and the button the childs of the child of the canvas?

cosmic dagger
rich adder
cosmic quail
rich adder
mellow elbow
dim halo
#

oh thx

#

Idid it

rich adder
mellow elbow
#

Thanks

#

ah I get it now

#

why not just use a regular if statement instead of returning if its not true

rich adder
#

You can .
idk wdym a regular if statemnt tho

#

how i wrote it prevents nesting

swift crag
#

"early return" can simplify functions

#
public void ReticulateSplines() {
  if (!ready)
    return;
  
  if (!splines.AskToReticulate())
    return;

  splines.DoReticulation();
}
#

you just quit the function early

mellow elbow
rich adder
swift crag
#

in this case it's not a huge difference

#

and I would probably use an if statement at that point

mellow elbow
cosmic dagger
mellow elbow
#

How

rich adder
#

StartCoroutine returns a Coroutine object

mellow elbow
cosmic dagger
#

Store the coroutine when you call StartCoroutine. Then check if the variable is null . . .

rich adder
swift crag
#

I wouldn't say it blocks anything, yes. It just stops early.

mellow elbow
#

I didnt mean it literally

#

but yeah

cosmic dagger
# mellow elbow How
// setup
var coroutine = StartCoroutine(SomeMethod);

// checking
if (coroutine != null) { return; }
mellow elbow
#

How does it return as null

cosmic dagger
mellow elbow
#

Thanks

dim halo
#

can someone tell me what is wrong with this code?

rich adder
#

thefore cannot use accessors

cosmic dagger
dim halo
#

how can I do that?

mellow elbow
mellow elbow
rich adder
dim halo
#

yeah my bad

#

thx guys

languid spire
cosmic dagger
median vapor
#

I have a problem where in my script function "PromjenaDepositZnakova" return true and the if statement doesnt run, it is true for 3 frames, so i thoth that was the problem then i used second variable that makes the "If" staement active until it is finish with the desiered actions but it didn't help, any ideas becouse i have no clue?

mellow elbow
#

nvm That's for a method woops

dim halo
#

I understand, thank you guys

eternal falconBOT
median vapor
rich adder
#

you code better and get you help here

burnt vapor
#

It will enable syntax highlighting and quick help

#

Alongside a bunch of other things

rich adder
mellow elbow
median vapor
#

ok

burnt vapor
#

No, configure your editor first, it's pointless to help before that.

swift crag
#

they said it shows you errors

rich adder
#

also please learn about arrays, whenever you start using numbering on variables you definitely need a collection

swift crag
#

they didn't ask to show the current errors

burnt vapor
#

My bad

mellow elbow
#

oh

languid spire
#

Also, Random.Range(0,1) aint gonna do a great deal

rich adder
#

also that Random.Range only return 0

#

(intiger version is max exclusive if you want 1, you always need +1)
Random.Range(0,2) // this gives 0 or 1

median vapor
#

That was me just testing something and messing around with values, later that random will be from 0 to 6 but the real issue is the If argument doesnt react to getting true from the function, ive configureded IDE.

swift crag
#

Do not use deltaTime with mouse input

#

you're getting a distance, not a velocity

#

so multiplying by deltaTime is incorrect

#

You'll need to adjust your sensitivity down a fair bit

#

It's a common mistake to make

#

You'll want to think about whether you have a distance (mouse input) or a velocity (joystick or keyboard input). If you have a velocity, use deltaTime to turn that into a distance.

#

and similarly...

float gravity = -9.81f; // acceleration
velocity += gravity * Time.deltaTime * Vector3.down; // velocity
transform.position += velocity * Time.deltaTime; // position
dim halo
#

can someone tell me why I cant move the number of 1

#

it is not moving

cosmic quail
rich adder
dim halo
rich adder
#

also are you using colliders for UI ? 🤔

dim halo
#

no?

#

I use colliders for objects

#

for pipes

rich adder
#

ohh i saw green box thought it was collider

dim halo
#

it's not

#

I cant move this number

#

it's so annoying

rich adder
#

wdym

dim halo
#

yes

#

Id did

rich adder
#

idk that size looks extremly large for that box for text

#

you should learn proper anchoring

swift crag
#

Yes -- check the docs in there

#

You should take a little time to read how RectTransforms work. It'll make your life a lot easier

#

I just kind of stumbled around blindly for a while before I actually read how stuff works

#

that was as error

#

Although, other than mouse input, I can't think of any common cases that get messed up

#

so that's most of what you need!

polar acorn
# dim halo

You're in play mode. Do you have code setting its position

#

You can't move something while code is setting its position -- it'll just move back to where it was

meager sentinel
#

Could someone help me with the ide of VSC?

polar acorn
#

Oh the bot is broken

eternal falconBOT
meager sentinel
#

i alr did everything

cosmic dagger
# meager sentinel Could someone help me with the ide of VSC?

VSC is difficult to get setup properly. If following the tutorial doesn't help, you're in uncharted territory. Try to redo it, make sure everything is closed beforehand, restart the computer, open Unity, double-click a script file to open up in VSC and hope it works . . .

languid spire
#

or, better yet, just use VS

rich adder
meager sentinel
rich adder
meager sentinel
#

i get an error that says something about a microsoft error

rich adder
#

show error

meager sentinel
#

WAIT WTH

#

It works now

#

the error dissapeared

#

and i had the error for like 2 days straight

cosmic dagger
#

That reminds me, I need to install and start using Rider. It's wasting away . . .

rich adder
#

u got it free?

meager sentinel
#

i had this error

rich adder
#

weird

cosmic dagger
rich adder
stuck palm
#

how do i access surface inputs in code?

rich adder
stuck palm
cosmic dagger
rich adder
rich adder
#

im on mac soo and m$ is stopping vs mac support in august so i either go full on VScode or use rider

swift crag
#

e.g. GetFloat/SetFloat

#

Note that you need to use the actual name of the property. The name you see in the inspector is generally different.

stuck palm
#

is there a getcolor

#

and set color

polar acorn
swift crag
#

One way to find out is to right-click on the shader dropdown and click "Select Shader"

#

so _BaseColor is the correct name to use if I want to adjust the property named BaseColor in the inspector

cosmic dagger
chrome wasp
#

Unfortunately im back with another issue

#
using System.Collections.Generic;
using UnityEngine;

public class X : MonoBehaviour

{
    public bool Turtle;
    public GameObject Bar;
    
     

    void Update(){
        if (Input.GetMouseButtonDown(0))
        {
            //cast ray from mouse position
            Vector2 clickPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(clickPosition, Vector2.0);

        }

Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);

         if (hit.collider != null && hit.collider.gameObject.CompareTag("X"));
        {
            Turtle = !Turtle;
        Bar.SetActive(Turtle);
        }


    }
     



    
}
#

getting some errors with that

#

Assets\X.cs(18,72): error CS1003: Syntax error, ',' expected

cosmic quail
chrome wasp
#

inside the code there are two things underlined in red. Vector2.0 and hit all on the same line

chrome wasp
#

it only goes up to 39

cosmic dagger
#

Column 72 . . .

cosmic quail
#

u mean Vector2.zero probably

chrome wasp
#

I'm not sure, I'm fixing my friend's code since he isnt on rn and I need to fix this

cosmic dagger
chrome wasp
#

okay so then there is hit

#

A local or parameter named 'hit' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

cosmic dagger
solemn summit
#

You'er raycasting twice and calling them both hit

#

Rename one of em

cosmic quail
chrome wasp
polar acorn
eternal falconBOT
cosmic quail
#

if they were in separate methods it would be fine. but in the same method, yeah u gotta change one of them

polar acorn
solemn summit
polar acorn
# chrome wasp yes

So then that combined with the error should be pretty obvious what the fix is

polar acorn
#

There's no such thing as Vector2.0

chrome wasp
#

I know

#

We already dealt with that

autumn arrow
#

is there any way to stop animation in milde of palying it ?

#

using script ?

chrome wasp
#

and it works but now says "There are 2 event systems in the scene. Please ensure there is always exactly one event system in the scene" but it works so

chrome wasp
polar acorn
polar acorn
solemn summit
meager sentinel
#

Ik this may be a very stupid question, since am new on doing particles, but how may i make that a particle appear exactly on where i want? (I have a GameObject that is supposed to be the place where it has to spawn)

chrome wasp
cosmic quail
polar acorn
meager sentinel
autumn arrow
#

im working o blocking system in sword combat and as soon as i hit a colider with tag enemy whle blocking i want to stop the animation and play the one that i got blocked

cosmic quail
chrome wasp
#

I will fix it

#

later

polar acorn
#

Just delete the extra one

solemn summit
cosmic quail
meager sentinel
meager sentinel
chrome wasp
# polar acorn Just delete the extra one

but im stupid and dont know which system is extra. i have two weeks to make a game and i dont know c# so im just trying to cobble it together. Im learning c# at the same time

cosmic quail
polar acorn
cosmic quail
chrome wasp
polar acorn
#

Did you rename them?

chrome wasp
#

No but there are two things and each are the same code but one is click position and one is mouse position

polar acorn
#

What does that have to do with the extra Event System

solemn summit
chrome wasp
chrome wasp
solemn summit
stuck palm
#

why isnt this working?

cosmic quail
polar acorn
#

called Event System

slender nymph
polar acorn
autumn arrow
solemn summit
cosmic quail
# chrome wasp is that not the second event sytem

alternatively it could be called something else if it was renamed. in that case click on the gameobject and in the inspector you will see a component called Event System. you should only have one of these in your scene

stuck palm
chrome wasp
#

weird well I ddeleted the game object called Event System

#

I do not even recall making that\

#

ever

cosmic quail
chrome wasp
#

what but now I have nothing called that in that section

rocky canyon
#

any suggestions on how to do the aiming mechanic for this?

quick breakdown its a point and click to move type bullet hell game where positioning is a core mechanic (autobattler) you'll end up moving by clicking the unit and drawing a path.. every X amount of mouse movement will trigger a new node/waypoint..

i dont want it aiming at the mouse all the time.. i'd want it to aim the direction its walking.. unless i give input to tell it to aim somewhere else.. (a general direction)
i was thinking like click and drag and release.. to give it a direction..
and since hes moving.. id have like a big buffer zone where u wouldnt need to click exactly on him, just nearby
but.. then once he gets to the next point he'll look the direction hes walking again.. or maybe he wont.. im unsure at this point.. just trying to think out the next system i gotta make

solemn summit
autumn arrow
#

folow the mouse mby ?

cosmic quail
chrome wasp
#

huh

#

now its telling me a tag isnt definied

#

i am going to lose it

polar acorn
chrome wasp
#

public GameObject ExitButton; does that not count

#

as defining it

polar acorn
chrome wasp
#

how do i define it then

polar acorn
#

First off, what is the exact error you're getting

chrome wasp
#

because it was working before when it was named X and there was no tag define

chrome wasp
#

Tag: X is not defined.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
X:Update () (at Assets/X.cs:26)

polar acorn
#

Add one

chrome wasp
#

so do I just throw GameObject.FindWithTag("ExitButton") at the top

cosmic quail
chrome wasp
#

okay

cosmic quail
#

ur code is looking for a tag named X so u gotta make a tag named X

polar acorn
safe barn
#

If you cant figure it out, just use GameObject.Find("yourgameobjectname");

polar acorn
#

Or: Best solution, don't use Find at all and just drag in the reference

cosmic quail
#

hes using CompareTag

chrome wasp
#
    ExitButton = GameObject.FindWithTag("ExitButton");
    Instantiate(ExitButtonPrefab, ExitButton.transform.position, ExitButton.transform.rotation) as GameObject;```
#

I followed the website

#

it still does not work

cosmic quail
chrome wasp
#

I dont need an X tag because Im just trying to deal with ExitButton

safe barn
#

So you do need an ExitButton tag

#

You do

polar acorn
#

Show it

cosmic quail
chrome wasp
#

but it never mentions X as a tag

polar acorn
#

Also your if statement contains nothing

chrome wasp
#
using System.Collections.Generic;
using UnityEngine;

public class X : MonoBehaviour

{
    public bool Turtle;
    public GameObject ExitButton;
    public GameObject Bar;

    void start()
{     
    if (ExitButton == null);
    ExitButton = GameObject.FindWithTag("ExitButton");
    Instantiate(ExitButtonPrefab, ExitButton.transform.position, ExitButton.transform.rotation) as GameObject;
}
    
     

    void Update(){
        if (Input.GetMouseButtonDown(0))
        {
            //cast ray from mouse position
            Vector2 clickPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D frog = Physics2D.Raycast(clickPosition, Vector2.zero);

        }

Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);

         if (hit.collider != null && hit.collider.gameObject.CompareTag("ExitButton"));
        {
            Turtle = !Turtle;
        Bar.SetActive(Turtle);
        }


    }
     



    
}
cosmic quail
#

ok u renamed the X to ExitButton

chrome wasp
#

yes

polar acorn
cosmic quail
#

all u need is to make an ExitButton tag then

safe barn
#

Add a tag to the GameObject

#

name it ExitButton

#

yes

queen adder
#

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

public class gunny: MonoBehaviour
{
public Transform bulletSpawnPoint;
public GameObject bulletPrefab;
public float bulletSpeed = 10;

void Uptade()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        Debug.Log("pressed");
        var bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
        bullet.GetComponent<Rigidbody>().velocity = bulletSpawnPoint.forward * bulletSpeed;
    }
}

}

eternal falconBOT
queen adder
#

oh mb

chrome wasp
chrome wasp
#
    ExitButton = GameObject.FindWithTag("ExitButton");
    Instantiate(ExitButtonPrefab, ExitButton.transform.position, ExitButton.transform.rotation) as GameObject;
}```
#

I thought that was making the tag

cosmic quail
polar acorn
safe barn
#

Not making it

queen adder
#
using System.Collections.Generic;
using UnityEngine;

public class gunny: MonoBehaviour
{
    public Transform bulletSpawnPoint;
    public GameObject bulletPrefab;
    public float bulletSpeed = 10;

    void Uptade()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("pressed");
            var bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
            bullet.GetComponent<Rigidbody>().velocity = bulletSpawnPoint.forward * bulletSpeed;
        }
    }
}
chrome wasp
#

i didnt scroll down 😭

queen adder
#

oh mb

#

tysm

chrome wasp
#

okay so

#

am I supposed to use ExitButton in that or respawn

polar acorn
chrome wasp
#

great okay I made a new tag called ExitButton

cosmic quail
chrome wasp
#

ok well now everything is broken

#

this has somehow broken another set of code

#

im just going to stop for a bit

polar acorn
chrome wasp
#

well we can blame my friend for that. I will let him now the script doesnt work

cosmic quail
chrome wasp
#

idk how he got it

#

the point is the raycast method he was trying to use worked for the dragging code he make

swift crag
#

The raycasting code makes zero sense.

#

maybe it can indeed work like Physics2D.OverlapPoint when the direction vector is Vector2.zero?

polar acorn
# chrome wasp ```using System.Collections; using System.Collections.Generic; using UnityEngine...

Let's see:

  1. start will never be called by Unity for similar reasons that other question we answered won't run Uptade
  2. If statement with nothing in it
  3. Instantiating a prefab that literally does not exist in the code
  4. The entirety of the first if statement in Update does nothing whatsoever. It spins up a few local variables, does nothing with them, then ends.
  5. Raycast with a direction of 0
  6. Superfluous boolean (with a very strange name) for toggling Bar, can just set the object's active state to whatever it isn't
#

D- see me after class

gusty hazel
#

hi im adding sounds to my game and ive got a audiomanager script https://hatebin.com/mpulbheocp attached to a game object tagged audio manager which doesnt destroy

#

but wether i put this AudioManager = GameObject.FindGameObjectWithTag ("audio"); in start or update it doesnt work

solemn summit
gusty hazel
#

just audio

slender nymph
#

Show the object and its tag

gusty hazel
rich adder
#

that else if statement is haunting

gusty hazel
#

thanks

solemn summit
#

AudioManager in your PlayerController is a GameObject. You'll have to get the AudioManagement component, will you not?

slender nymph
#

This whole setup is haunting tbh

gusty hazel
#

ive tried that too

gusty hazel
#

but that also doesnt woek

slender nymph
gusty hazel
rich adder
gusty hazel
#

the rest of my code uses references promise

polar acorn
#

No cop would convict you

gusty hazel
#

teacher :p

rich adder
#

bad teacher

gusty hazel
#

fr

solemn summit
#

I don't think I have ever typed the words SendMessage before in my life

rich adder
polar acorn
#

SendMessage is an ancient solution to a problem that existed fifteen years ago and should have been removed when they removed .collider and the like

swift crag
gusty hazel
#

im using Unity 2018.2 and Monodevelop

swift crag
#

with no ability to specify the signature of the method ahead of time

solemn summit
#

Anyway, we've dogged on the setup, what are people's recommendations for a rework here?

gusty hazel
#

cant even use a newer unity bc its coursework

#

and got to do it on school computers

swift crag
#

i'm developing some Opinions over here

rich adder
polar acorn
swift crag
#

If you need to call Bar, a method that's part of a class named Foo, you should get a reference to the object and call the method directly.

[SerializeField] Foo myFoo;

void DoSomething() {
  myFoo.Bar();
}
wanton cargo
wanton cargo
#

Like I said I'm not sure where to ask this

rich adder
wanton cargo
#

Ok thanks I'll ask there

swift crag
#

and it's a lot more efficient to call a method instead of using SendMessage

#

Unity has to go rooting around in the guts of the target to see if a method with the appropriate name exists

solemn summit
#

Or be incredibly lazy like me and learn Singletons and abuse them so badly but never let anyone look at my code

rich adder
#

Singletons get unnecessary bad rep

gusty hazel
#

will finding the component through start work if it is on Dontdestroyonload

#

or should i just put it on each scene

rich adder
cosmic quail
#

every good game has dozens of singletons

rich adder
#

you can use a singleton though

swift crag
#

I forget how the Find methods work with multiple scenes

rich adder
#

iirc they do not last I tested

swift crag
#

If the "Audio Management" component is getting punted to another scene, then I think it's very reasonable to just make it a singleton

eternal needle
swift crag
#

hot take: singletons are dependency injection

rich adder
swift crag
#

your object gets its value from somewhere else

eternal needle
#

Or the other one people say, mock testing

rich adder
#

anytime I make a ASP.NET app I have DI + there is a AddSingleton for it

swift crag
swift crag
#

a singleton is something that exists exactly once

#

If you have many copies of something, you can't just say "give me X" and get the exact instance you wanted

#

if there are 10 enemies, you can't just...pick one at random to deal damage to

#

But when there's exactly one instance of something, you can always get exactly the instance you wanted

#

The easiest way to make a singleton is to do something like this

#
public class AudioSystem : MonoBehaviour {
  public static AudioSystem instance;

  void Awake() {
    instance = this;
  }
}
#

you can now reference the audio system from anywhere as AudioSystem.instance

#

(not in other Awake methods, since they might run before the AudioSystem's Awake does)

#

This is not the best way to do it for a few reasons (the timing issue, nothing stops you from making multiple instances by mistake..)

#

But I think it's very serviceable here.

#

Before you make something a singleton, you must ask yourself if it's truly only ever going to exist once.

#

Oftentimes, singletons will be "manager" types

#

look at my cute little managers

rich adder
#

I access my other managers by 1 main manager so I just make that the singleton and grab the rest with props,
imo no need to make 20 diff managers singletons

swift crag
#

the Game one is mislabeled

#

don't tell anyone 🤫

solemn summit
#
private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }
#

Just to keep things clean

swift crag
#

I have one true god-manager -- the GameController -- that lives forever and keeps track of high level game state

#

and then I have others that only survive for a single scene

swift crag
#

it's the Encounter Manager now. it handles a single encounter in the game

rich adder
#

MainBoss

#

xD

swift crag
#

i'm having animation nightmares today and I still have a cold, so I'm taking it easy lol

cosmic quail
swift crag
#

I prefer not to cache when it's such a tiny thing, personally

rich adder
swift crag
#

Unless it's a mega-hot code path

#

that'd still be really marginal

rich adder
#

yea

swift crag
#

If I have a loop that runs 20,000 times per frame, I store the value I got from a dict instead of reading it thrice

#

Although, it can be hard to tell how important those tiny function calls actually are.

#

Deep Profile adds a huge amount of overhead to each function call, so lots of tiny calls get blown out of proportion

#

(I did still see a minor gain in regular profiling in that case)

buoyant knot
#

Debug.Assert becomes super expensive in deep profiling

#

especially if you have a formatted/concatenated string message

eternal needle
#

Debugging or writing is always expensive, concating strings is also a bit of allocations

queen adder
#
using UnityEngine;

public class Bullet : MonoBehaviour
{
    public GameObject impactEffect;
    public float life = 3;

    void Awake()
    {
        Destroy(gameObject, life);   
    }

    void OnCollisionEnter(Collision collision)
    {
        if(collision.gameObject.tag == "enemy")
        {
            Destroy(collision.gameObject);
            GameObject ImpactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(ImpactGO, 2f);
        }
        Destroy(gameObject);
    }
}
lament sable
#

Hello, i am new at unity and i need help with sharing variable between 2 scripts my first script has a correct value of 2 and my second script has a value of 0 that's probably because the value cannot be shared to the other script.
Is there any way I can fix it?

queen adder
#

how can i change this hit to like collide or something bcs i copied it from raycast thing

sage mirage
#

Hey, guys! I have a question. How to don't give permission to the player to interact with any button before the game starts, for example I want to make a functionality that the player enters the main scene of the game and when it enters then to give the permission to the player to interact?

polar acorn
polar acorn
#

!code

eternal falconBOT
sage mirage
#
{
    if (Input.GetKeyDown(KeyCode.Space) && uiManager.pauseIsActive == false)
    {
        playerRb.AddForce(Vector3.up * jumpForce, ForceMode2D.Impulse);
        audioManager.PlayerJumpSound();
        Debug.Log("We give force to the player!");
    }

    else if (Input.GetKeyDown(KeyCode.Space) && uiManager.pauseIsActive == true)
    {  
        audioManager.jumpSoundAudioSource.Stop();
    }
}```
#

I am giving force to the player with a space button here!

polar acorn
short hazel
sage mirage
lament sable
polar acorn
polar acorn
eternal falconBOT
lament sable
polar acorn
pallid verge
#

does this code look fine cuz it doesnt work but i dont see anything wrong with it

#

whenever the player collects a battery the battery is SetActive(false)

#

and the tag name is right

short hazel
#

Find methods don't find inactive objects

polar acorn
pallid verge
short hazel
#

No because Find doesn't find inactive objects

pallid verge
#

ohhh

polar acorn
#

Returns one active GameObject tagged tag

pallid verge
#

what if i make that array at the start of the game?

#

when all the batteries are active

#

will it store them even when they are inactive

short hazel
#

Yes that is an option

polar acorn
eternal falconBOT
lament sable
crisp tulip
#

!code

eternal falconBOT
short hazel
#

Open one of the websites. Paste the code. Click the "Save" button.
The URL will be replaced with a link to the paste, copy and paste it here

polar acorn
slender nymph
# lament sable

you're supposed to share the URL, not paste it to the site then download it and upload it to discord

misty hedge
#

I'm trying to figure out the best way hypothetically to effectively store lines for a game in an organised and expandable way.
I discovered json, which seems like a pretty solid way to do it, but because this requires an object type to be defined to be serialised to, I don't think this would be the ideal use case for it as I don't want to make a new object for every line.

rocky canyon
#

why not use 1 type.. with as many ever properties as you need?

polar acorn
misty hedge
#

ah! I did not know that

#

That solves the problem, thank you

lament sable
# polar acorn Put the code on a paste site. Put the URL here

https://hastebin.com/share/duremowage.csharp and https://hastebin.com/share/oligicisek.csharp I don't know why the 'level' is not the same for both can sommme wan exsplane what is wrong

polar acorn
#

They have nothing to do with each other

lament sable
#

theye are conected by the [SerializeField] public StarterTexstScript starterTexstScript; and [SerializeField] public Doorscript doorscript;

polar acorn
#

You have a reference to the other script but you aren't using it anywhere

#

You are just using this script's level variable

lament sable
#

how do I fix it than Idk what I can do about that ?

polar acorn
lament sable
#

yes but how ?

polar acorn
lament sable
#

what I don't get it

rocky canyon
#

theOtherScript.level =

#

if you just say level = your basically saying this.level = which is the level within that class

polar acorn
lament sable
#

like dis ? : Doorscript.level

polar acorn
rocky canyon
#

u don't use the Type

lament sable
#

but there is a red line under it

rocky canyon
#

you use the name you gave it

polar acorn
lament sable
rocky canyon
#

negative

polar acorn
lament sable
#

br pls I don't know

polar acorn
#

Do not have a variable level on this script

rocky canyon
#

public DoorScript doorscript;

doorscript.level

#

you have 2 different levels in ur scripts.. one belongs to one script the other belongs to the other script..

if ur in one script and you want to access the level in the other script.. you have to use the variable OF that script..

#

but WITH the name

lament sable
#

that is in my script

polar acorn
lament sable
#

so if (doorscript.level == 2){}

swift crag
#

[SerializeField] <-- asks Unity to store this field, even if it isn't public
public <-- allow anyone to see the field
Doorscript <-- this field holds a "Doorscript" object
doorscript <-- the name of the field

#

the name of the field is the only part you need to write to access the field.

rocky canyon
#

makes sense to me

swift crag
#

if it worked, you wouldn't be here asking about it!

#

in what way does it not work?

lament sable
#

the eror is :
'Doorscript.level' is inaccessible due to its protection level

polar acorn
rocky canyon
#

protection level.. thats the public, private, static part u put before the type u declared

lament sable
swift crag
#

well, it sounds more like the code doesn't even compile

rocky canyon
#

public means u can access it anywhere.. private means you can only access it in the script that it sits in, and static isnt important right now..

#

well..

polar acorn
rocky canyon
#

u can't access a private variable from an external script..

#

you need to use a public variable.. if u want to access it from other places..

#

i dont think he's using his brain.. other than fishing for exact solutions

lament sable
#

I don't know what is ronge but I am gane restart my pc so bey I tink i fix it btw

swift crag
#

restarting your computer will not fix your code.

lament sable
#

it works sorry there was a other mistake sry bey

swift crag
rocky canyon
#

🍀

rocky canyon
swift crag
#

oh i could parse the sentence

rocky canyon
#

lol i almost couldnt

polar acorn
swift crag
#

i was just pondering the situation as a whole

rocky canyon
#

variables..

#

complicated stuff

#
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            gameIsPaused = !gameIsPaused;
            PauseGame();
        }
    }

    void PauseGame()
    {
        if(gameIsPaused)
        {
            Time.timeScale = 0f;
            pauseNotif.SetActive(true);
        }
        else
        {
            Time.timeScale = 1;
            pauseNotif.SetActive(false);
        }
    }``` i thought when you set timeScale to 0 the update stops
#

guess thats not teh case

slender nymph
#

no, update is still called. but deltaTime will be 0

rocky canyon
#

ahh so its fixedupdate

#

ya, i just had em mixed up

#

thats great news tho, i was thinking id have to do something complicated to achieve a pause

swift crag
#

that caused some funny problems for me (division by zero)

rocky canyon
#

hehe.. still a few things to work out

misty hedge
#

I may be stupid but I'm at a loss. Trying to read this simple array from a file is so far doing nothing...

swift crag
#

That class does not match your data

#

Your data contains a single object. The object has one name -- "Scene" -- and one value -- an array of strings

#

Your Scene class has a single array of strings named "Lines"

#

These do not match at all.

polar acorn
swift crag
#

Each field on your class will become a name in an object. So you'd better have "Lines" somewhere in your JSON!

#

^ and yep, just produce an example to look at

misty hedge
#

Aeugh. I haven't used JSON since modding minecraft years ago and it shows

#

I will produce an example then!

olive lintel
#

Hey guys, I was trying to see if theres a simple way to find the total length of a slerp curve, as in, vector3.distance between 2 points, however while accounting for a third midpoint somewhere. I did find the following solution:

 Vector3 previousSample = A;
 float distance = 0;
 for (int i=1; i<sampleCount; i++) {
     Vector3 sample = Vector3.Slerp(A, B, (float)i/(float)sampleCount );
     distance += Vector3.Distance(sample, previousSample);
     previousSample = sample;
 }```
but it seems rather crude and I was wondering if theres a simpler/mathematically perfect solution out there?
wintry quarry
olive lintel
wintry quarry
#

It's odd to be doing slerp between non-unit vectors

swift crag
#

It's non-trivial for two differently sized spheres

#

It's pretty reasonable!

#

I've used it for moving a look target from place to place

wintry quarry
#

I would think you just take the average of the two circumferences if they're not the same length

swift crag
#

(well, I really did a cylindrical lerp, but that's just XZ slerp + Y lerp)

#

I think I looked into this before. I didn't get a good answer.

#

You can approximate it by just sampling a bunch of points, of course. Looks like that's what you did.

pallid verge
#

what would this error mean? this is the script

#

it doesnt give me any errors in my ide

ancient island
#

hey guys, I have an animation that rotates an object clockwise by 360 degrees forever (in case you ask, yes, I need an animation because then I can take advantage of animation speed). In a given moment I need to stop the animation at whichever rotation the object is and make it return to its original rotation (0, 0, 0) in exactly 2.25 seconds. any idea about how to achieve this?

swift crag
slender nymph
olive lintel
swift crag
#

The average radius is probably an okay approximation

slender nymph
swift crag
#

If you want to be able to vary the speed, just...change the amount you rotate by

slender nymph
#

again, scale value for controlling the speed

polar acorn
solemn summit
slender nymph
#

in fact, you would have more control over the speed if you do it via code

pallid verge
slender nymph
#

it could be that, or it could be your singleton instance

pallid verge
#

idk what that means

polar acorn
pallid verge
swift crag
#

why would they? you never reach them in the first place

slender nymph
#

it wouldn't reach the next line of code

polar acorn
pallid verge
#

oh

swift crag
#

You'll see errors in your IDE when there's something provably wrong with your code

#
int x = 3.5f;
#

this is a compile error because you can't assign a float into an int variable

#
var foo = GameObject.Find("What");
foo.name = "Hi!";

This will throw an exception unless there happens to be a game object named "What" in your scene. The compiler can't prove that, though. Everything is structured perfectly correctly.

misty hedge
#

Figured out how to serialize and de-serialize JSON properly for strings and integers, but noticed this in the documentation:
Unity does not support passing other types directly to the API, such as primitive types or arrays. If you need to convert those, wrap them in a class or struct of some sort.
I'm not quite sure what it means by 'wrap them in a class.'

pallid verge
#

alright so i think i found my error, that applyalloptions method is called in a Load method and that Load method is called in Awake

#

could that be it?

#

because awake is before the first frame so the audiomanager doesnt exist yet

swift crag
#

The corresponding JSON would be

["a", "b", "c"]

and

{ "strings": ["a", "b", "c"] }

respectively

misty hedge
#

Oh wow, thank you! That's exactly what I needed to know

timber tide
slender nymph
#

this is a code channel

keen ice
#

To block a animation

swift crag
# timber tide well, you can probably get the time between the start and end keyframes and norm...

this sounds a lot harder than being able to just do...

[SerializeField] float spinRate;
private float returnRate;
private bool spinning = true;

void Update() {
  if (spinning)
    transform.Rotate(0, Time.deltaTime * spinRate, 0);
  else
    transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.identity, returnRate * Time.deltaTime);
}

public void Return(float duration) {
  spinning = false;
  returnRate = Quaternion.Angle(transform.rotation, Quaternion.identity) / duration;
}
#

that'd do the trick!

timber tide
#

yeah if you just wanna do it without the animator

keen ice
#

oj my bad

timber tide
#

but if the clip is just a rotation then yeah use rotational methods

fringe kindle
#

Trying to add a countdown timer to the start of my game but when I press E (the key to activate it), it just goes on to 3 and stops there.

misty hedge
#

There we go, I can work with this now. Tysm for the help!!

swift crag
#

If you want to do more complex serialization (like serialization of dictionaries), consider Json.NET

polar acorn
fringe kindle
polar acorn
#

A deactivated or destroyed object ends all coroutines

fringe kindle
#

Some of the objects parented to UI get disabled, as part of the countdown process

#

but other than that, that's pretty much it

polar acorn
fringe kindle
#

No

polar acorn
#

the one the coroutine is running on

polar acorn
fringe kindle
#

Timescale at the start is 0

#

Should've shown that as well as the void update

polar acorn
fringe kindle
#

Ah

tawdry rock
#

Anyone can help? I want to create bullet holes on wall and i having these flickering images.
I made a Quad, inside a new gameobject with sprite renderer and i attached my bullet hole. Made a material for it then prefabed it.
Code im using:

 if (hit.collider.CompareTag("wall"))
 {
       Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal * 0.025f));
     
 }
fringe kindle
#

Is there another way to pause everything without affecting WaitForSeconds?

polar acorn
# fringe kindle Is there another way to pause everything without affecting WaitForSeconds?

Learn how to pause your game in Unity in less than 2 minutes without setting timescale using events.

This allows you to still use time-based logic in pause menus and background systems and can even be extended to work for cutscenes, loading screens and game over screens.

TIMESTAMPS
00:00 Intro
00:05 Game State Manager
00:51 Hook up Player Move...

▶ Play video
waxen oracle
#

Is there any definition for something like child in the transform?

#

or children

polar acorn
#

There are many methods and functions at your disposal

golden otter
rich adder
swift crag
#

FromToRotation just goes between two directions.

#

Did you want to offset the bullet hole from the wall? You need to add hit.normal to the position you spawn at.

tawdry rock
#

Yes, URP but i can't find where could i enable decals, also i using multiplying so the hole wont appear on the surface of the wall to prevent flickering but it not works.

fringe kindle
lone finch
#

Im trying to make a disjointed hitbox to detect ground collisions, but it dosen't seem to be working. What could i be doing wrong? `{
public GoblinMoves myGoblinMoves;
public GameObject myGoblin;
public float yValue;

private void Update()
{
    yValue = (float)(myGoblin.transform.position.y - 0.03);
    transform.position = new Vector3(myGoblin.transform.position.x, yValue);
}
private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.collider.gameObject.layer == LayerMask.NameToLayer("Ground"))
    {
        myGoblinMoves.jumpSpeed = myGoblinMoves.jumpSpeedControl;
        myGoblinMoves.jumpCount = 0;
        Debug.Log("Detected Collision");
    }
}

}`

#

to clarify i get no collisions

polar acorn
#

see if you're colliding with anything at all and if that thing is the object you expect it to be

tawdry rock
rich adder
tawdry rock
rich adder
smoky niche
#

Hey there, does anyone here have any experience with the System.Diagostics.Stopwatch? Is it more accurate than Coroutines or timers in an Update loop?

polar acorn
# lone finch apparently not

The Three Commandments of OnCollisionEnter2D:

  1. Thou Shalt have a 2D Collider on each object
  2. Thou Shalt not tick isTrigger on either of them
  3. Thou Shalt have a 2D Rigidbody on at least one of them
tawdry rock
golden otter
lone finch
#

also whats the easiest way to disable physics

smoky niche
#

So is there any way to accurately check for milliseconds

#

Since coroutines and normal timers don't seem to be millisecond accurate

golden otter
#

why do you need ms accurate methods?

vale geode
#

hi can i ask for some help?

shell sorrel
# smoky niche Oh alright thanks!

anything you do in unity will be happening on a frame, so you can can accurately mesaure time but your code will all be executing on frames

smoky niche
# golden otter why do you need ms accurate methods?

I'm making a game where you have a couple of invincibility frames if you get hit and use a coroutine for it. The difference in time is always a bit different though, and I would want it to be as accurate as possible since it's a precise platformer game

golden otter
vale geode
#

im having some problems with a ray not apearing in the scene i dont know what to do

polar acorn
#

You physically cannot interact with anything between frames

golden otter
#

!code

eternal falconBOT
rich adder
#

!code

polar acorn
#

so it really doesn't matter if your timer is up on a frame or between them

eternal falconBOT
rich adder
#

ur supposed to like read the massage bruh

desert elm
#

question, is it possible to run the game window at one frame intervals?

polar acorn
desert elm
#

oh okay

rich adder
polar acorn
#

Run the game, pause it, and you can frame-by-frame with the third button

smoky niche
tawdry rock
#

well my bullet holes are worse now thru decals

rich adder
vale geode
#

´´´cs

tawdry rock
polar acorn
slender nymph
rich adder
# tawdry rock

weird I dont get Zclip. Try moving it slightly outward from normal

tawdry rock
vale geode
#

im not really understanding how to use the sites

vale geode
#

sorry

polar acorn
rich adder
buoyant knot
#

Coroutines are good to delay something by some amount of time and/or frames.

vale geode
#

yes the script is running and i saw the ray line but somehow it stoped working when i switched to private the (public camera cam)

polar acorn
rich adder
vale geode
polar acorn
vale geode
polar acorn
rich adder
#

tisk tisk

vale geode
#

main camera?

rich adder
#

you see what you're doing here?
cam = GetComponent<Camera>();

polar acorn
#

So the code is doing exactly what you asked

#

You only draw the ray if this object has a Camera component on it

#

since it doesn't have one, you don't draw the ray

vale geode
#

but the camera is set as child on the object

polar acorn
vale geode
#

do i drag it in?

polar acorn
#

you're checking this object

#

which doesn't have one

rich adder
#

GetComponent will override the inspector, always

#

you had it assigned but at runtime it was null

vale geode
desert elm
#

is there a default circle outline sprite in unity?

rich adder
desert elm
vale geode
#

the red ray is what i wanted to see and was working before, but when i press play i have to select the camera on inspector, i didnt figure out to to put the camera in the inspector from the hierarchy

rich adder
slender nymph
#

it's because you were overwriting the already assigned camera with your GetComponent call

misty hedge
#

Because I've been sitting here for a while pondering this, I'm wondering if there's a better way to do it.

I want some dialogue to trigger a delay, so there's a few seconds of nothing before another line pops up. The way I was going to implement this was have some lines in the text file simply say "t=5", and when I read the dialogue, these get omitted and a separate list tracks when the current line index matches this delay index, and waits.

Does Unity have any built-in systems to handle events like this that would be less crude and easier to edit?

frosty hound
#

No, you either make it yourself, or you use very well done assets like Text Animator off the store.

vale geode
#

i did it its working

queen adder
#

Hi, my project is on unity vers 2021.3.18f1, I have the input system version 1.4.4 but I need 1.7 for a certain feature. How can I get 1.7 in my project instead?

misty hedge
#

Alright. I think I'll step back and make a proper event scheudling system for my games instead of continuing this hacky one, then

queen adder
rich adder
#

doc says 2019+

queen adder
rich adder
#

maybe remove it and try adding again

queen adder
rich adder
# queen adder

did you add via git or something?
Remove and try adding it from the Unity Registry in PM

queen adder
#

Yeah i just did that still stuck on 2022s 1.4.4

#

I dont need to have the 2023 version of the editor installed to have the 2023 vers of these features right?

rich adder
#

no I just showed you works fine on 2021

#

something wrong with your package manager or something

queen adder
#

ok

desert elm
#

is it possible to have something like the SpriteRender.enabled = false be applied to children as well>

wintry quarry
#

e.g.

foreach (Renderer r in GetComponentsInChildren<Renderer>()) r.enabled = false;```
desert elm
#

oh thanks

past brook
#

how do i make it so when the player gets close to grapple point the grapple disables and they get "launched" from the grapple like when they swing off instead of the current dead stop

vernal minnow
#

Is there a proper way to code and comment? I was reviewing my code and realized that not only is it messy, but sometimes I'm rarely commenting and sometimes I have comments on every/every other line

#

It makes sense to me but I feel like it will make it difficult for others to read

rich egret
#

hi i need help
Enemy Code:

using UnityEngine.SceneManagement;

public class EnemyController : MonoBehaviour
{
    public float health = 100f;

    // Function to apply damage to the enemy
    void Update()
    {
        if (health <= 0)
        {
            Die();
        }
    }

    void Die()
    {
        Debug.Log("Enemy died!");
        // Additional logic for enemy death can be added here
        Destroy(gameObject);
    }
}```

**Gun Code:**
#

The bullets don't hit the enemy, what to do?

eternal falconBOT
rich egret
#

ok

summer stump
idle elk
#

https://hastebin.com/share/edoqocoguc.csharp does anyone can help me solve this .. basically this code to collect calorie and stone .. i want to save only stone and appear in other scene .. but only Stone1 appear... and if i put 3 or 4 Stone in 1 scene ..it can save and appear in scene display ..can someone help me

short hazel
polar acorn
rich egret
wintry quarry
#

Do you have a script on the bullet perhaps?

#

Also what components does the bullet have and the enemy?

#

Also this is weird:

                if (hit.transform.tag == "Enemy")
                {
                    hit.transform.gameObject.GetComponent<EnemyController>().health -= Random.Range(hit1, hit2);
                }```
It seems like you're spawning a projectile but you're also doing this and using a raycast?
rich egret
wintry quarry
#

Which one are you using?

#

Raycasts or projectiles?

#

Pick one

polar acorn
rich egret
polar acorn
#

Second, log the object your raycast hits. If you're getting bullets to spawn at all, then the ray is hitting something. That thing might not have the Enemy tag

rich egret
#

I thought it would be more convenient

rich egret
#

Does anyone have a solution to fix this? There is no clear enough guide on the Internet

polar acorn
polar acorn
rich egret
polar acorn
rich egret
#

ahhhhh

#

nothing

polar acorn
rich egret
polar acorn
#

Log the object your raycast hits

#

see if that has the tag Enemy

rich egret
#

But I already tagged him an Enemy!

polar acorn
#

how do you know that the ray hit that object

wintry quarry
rich egret
polar acorn
#

At no point did I ask "Is there an object in your project tagged Enemy"

#

I asked "Is the object your raycast hits tagged enemy"

#

Now put the fucking log in

rich egret
#

ok

#

🥲

frosty hound
#

@rich egret If you're not going to actual log your issue, as you've been asked multiple times, stop posting.

polar acorn
#

Show what it prints

#

Until you do, no one can solve your problem

meager sentinel
#

I place this here since i kinda think this may be via code, but. I have a particle system that triggers when you have contact with an enemy, the thing is, it's supposed to be blood. But if u move when the particle system is working, the blood will stay where you walk, how can i make the particle system to not move after being executed? Or what's the line of code to execute it at a certain location

polar acorn
frosty hound
meager sentinel
#

Thank you both

rich egret
summer stump
rich egret
polar acorn
#

then check the tag

#

We already know this is not running

#

that's why I told you to log the object your ray hits

#

not inside an if

summer stump
#

Log the raycasthit (not a random word) "Before" any conditions.

polar acorn
#

just log the object

#

see what object the raycast hits

meager sentinel
polar acorn
meager sentinel
#

I opened all of the things and i dont find it

meager sentinel
#

and then u place it on world

#

ty

rich egret
#

ok like this? @polar acorn

polar acorn
#

how did you possibly think this was related to what I asked

summer stump
#

The log should be inside the gun script, just after the line you call raycast. And it should log the object returned by the raycast (called a RaycastHit). You have it declared as "hit"

polar acorn
#

Log

#

the

#

object

rich egret
polar acorn
#

your

#

raycast

#

hits

rich egret
#

like this?!!!!

polar acorn
#

what does it say

rich egret
#

wait