#💻┃code-beginner

1 messages · Page 557 of 1

brittle maple
#

I will try this, thanks!

scarlet hull
#

how can i know whats going to be the last screen scalling?

#

looks right in 1x scaling but bad with 0.25x

#

how do i know where i should place this chatbox

#

could anybody try helping me

obsidian plaza
#

and make the images you import the exact pixel size without scaling

#

for example 8x8 is just 8 by 8 pixels

obsidian plaza
#

then turn off compression and change pixel size

#

then just zoom your camera in

scarlet hull
#

yeah i have got that

#

drawing and importing stuff

#

another little issue tho

#

do you know why its showing this X?

#

only happens when i set ref resolition to 1920 x 1080

brittle maple
#

I either dont know how to implement/use this or its not working. Dx this has stumped my progress for a week.

naive pawn
#

what's your code?

obsidian plaza
#

nah idk maybe those are 0 opacity pixels or smtn

brittle maple
cosmic dagger
#

how are you moving the object. show your !code . . .

eternal falconBOT
brittle maple
#

yes yes, wait, it takes time

scarlet hull
runic lance
obsidian plaza
#

scale with pixel size or something like that

brittle maple
runic lance
#

you need to have a CanvasScaler component so that the UI scales properly

naive pawn
#

you need to do totalMovement = transform.TransformDirection(...)

obsidian plaza
#

and change scaling

brittle maple
scarlet hull
runic lance
# scarlet hull

try clicking the blue arrows on the transform component and select the red center one, then you should be able to visualize the negative components

scarlet hull
#

what do i need it to change it to

obsidian plaza
#

i think

naive pawn
#

@brittle maple also note that TransformDirection has an overload to accept x, y, z separately, so if you feed the direction in directly you don't have to wrap it in a Vector3

scarlet hull
#

nope its still not working

runic lance
# scarlet hull

yeah it needs to be on the Canvas only, not on your image
then you should configure it properly

obsidian plaza
# scarlet hull

does that fix the resolution issue? thats what i was tryna do

brittle maple
naive pawn
runic lance
#

I would also suggest not changing the image scale manually, always leave it as 1
and check what's causing the negative height/width, otherwise it might not work as expected

#

and it would probably be better to move this question to #📲┃ui-ux as it has nothing to do with code

brittle maple
cosmic dagger
naive pawn
#

that doesn't make sense

brittle maple
cosmic dagger
#

also, you don't need gameObject, you can just do transform.blah . . .

naive pawn
brittle maple
naive pawn
#

TransfromDirection just turns a local direction into a world-space direction
linearVelocity is world-space
currently, totalMovement is local-space

naive pawn
brittle maple
naive pawn
#

and those somethings would be what you had inside the new Vector3 that you assigned to totalMovement before

brittle maple
naive pawn
#

yeah, then you won't need that first assignment

brittle maple
naive pawn
#

"didn't work" doesn't really tell me anything

elfin isle
#

heyy!! i was here awhile ago and had a bug that i couldnt fix and never got it fixed.

could anyone help me with a raycasting script absolutely refusing to work? i've followed a good bit of tutorials and don't know a ton a bout raycasting

my goal is f or the player to look at an object, and press "E" and upon doing so it responsds with Debug.Log("hi");

brittle maple
elfin isle
#

ALSO SORRY TO INTERRUPT YOU CAN IGNORE ME !!

cosmic dagger
#

stop with the caps, please . . .

naive pawn
#

just the Update code is fine, you don't need to show the whole script

naive pawn
#

what's your code?

elfin isle
# naive pawn what's your code?

sorrry uhhhh heres the script for the camera

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

interface  IInteractable 
{
    public void Interact();
}
public class Interactor : MonoBehaviour
{

    public Transform InteractorSource;
    public float InteractRange;
    LayerMask _mask;
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            Ray r = new Ray(InteractorSource.position, InteractorSource.forward);
            if(Physics.Raycast(r, out RaycastHit hitInfo, InteractRange, _mask))
            {
                Debug.Log("raycast hit");
                if (hitInfo.collider.gameObject.TryGetComponent(out IInteractable interactObj)) 
                {
                    interactObj.Interact();
                }
            }
        }
    }
}
#

andd heres the script for the object that is being interacted w ith (and yes, i've tried debugging)

using UnityEngine;

public class TestInteract : MonoBehaviour, IInteractable
{
    public void Interact()
    {
        Debug.Log("hi");
    }
}
silk meteor
#

so I play this sound every time the player jumps:

    public void OnJump()
    {
        if (body.gravityScale == 0)
            body.gravityScale = gravityScale;
        body.linearVelocity = new Vector2(body.linearVelocityX, jumpForce);
        audioSource.PlayOneShot(jumpSound);
    }```
however, the sound plays twice, is there a reason why?
brittle maple
# naive pawn what's your current code?

Aight, so its solved (I hope forever) In all this code messing I seem to have deleted the part that was rotating my Player gameObject, I will do some debugging and testing, thanks!!!

cosmic dagger
silk meteor
#

it plays 3 times

#

how can i fix it?

#

im using unitys new input system btw

cosmic dagger
#

this happens every time you jump?

silk meteor
#

yes

#

press space or left mouse button

cosmic dagger
#

if so, then you appear to be jumping or pressing the button three times . . .

silk meteor
#

i don't think so

cosmic dagger
#

how do you track the button press?

silk meteor
cosmic dagger
#

if you hold the button down, does it keep logging?

silk meteor
#

nope

cosmic dagger
#

do you have duplicate PlayerInput scripts on other GameObjects?

silk meteor
#

wait i think i know why

#

its because im jumping every time the key is interacted, rather than only when pressed down

#

now the player doesn't jump at all

#
    public void OnJump(InputAction.CallbackContext context)
    {
        if (context.started)
        {
            if (body.gravityScale == 0)
                body.gravityScale = gravityScale;
            body.linearVelocity = new Vector2(body.linearVelocityX, jumpForce);
            audioSource.PlayOneShot(jumpSound);
        }
    }```
rich egret
#

Does anyone know how to take a picture over terrain?

silk meteor
#

change its order in layer / sorting layer?

elfin isle
frail hawk
#

do you get any debug logs in the console Zack

elfin isle
#

None

frail hawk
#

your LayerMask is not assigned

#

[SerializeField] LayerMask _mask and assign the layermask from the inspector

#

also make sure you interactables have a collider

#

and first parameter inside the Raycast has to be a Vector3 not a Ray

elfin isle
#

what should my layermask be?

i had it on "everything"

frail hawk
#

i am really surprised you dont have any errors

#

well a layermask for all of your interactables.

elfin isle
#

Ray r = new Ray(InteractorSource.position, InteractorSource.forward);
this one?

frail hawk
#

(Physics.Raycast(r, out RaycastHit hitInfo, InteractRange, _mask)) < this

elfin isle
#

oh

frail hawk
untold shore
#

Hey quick question. Trying to put my prefab text (the HandValueText) into the cardimagerandomization script (I know that wording is weird, but that script has the handValue already in it.) HandValueText is TextMeshPro, but whatever I set the script class to, it won't let me put HandValueText in there. Any ideas?
Code:

 public Text handValue;

    public void Start()
    {
        hand  = GameObject.Find("HandPosition");
        
        AddCardImage();
        hand.GetComponent<CardValuesScript>().handValue = hand.GetComponent<CardValuesScript>().handValue + cardValue;
        Debug.Log($"CardValue " + cardValue);
        UISprite.sprite = cardSprite;
        handValue.text = "HandValue: " + hand.GetComponent<CardValuesScript>().handValue.ToString();
    }
``` Thanks!
obsidian plaza
#

isnt that the built in unity one

untold shore
#

Mhm, I just dont know what do put there instead of text. I've tried TextMeshPro, TextMeshProGUI, and TextMesh too

obsidian plaza
#

also brother just make a variable so u dont have to getcomponent so much

frail hawk
#

TextMeshProUGUI <

#

not TextMeshProGUI

frail hawk
#

don´t you have intellisense

untold shore
#

I do - just didnt copy over right here

frail hawk
#

as asa said, import the namespace TMPro

untold shore
#

Sorry, still new to all this 😅 It worked, thank yall!

obsidian plaza
#

ur good

elfin isle
frail hawk
#

then mate you really have to learn the basics of c#

#

and fix your IDE so you see the console errors, ther eshould be at least 2 in your case

elfin isle
#

no i mean- ugh i know the basics of c# im just not understanding why this still isnt working

elfin isle
frail hawk
#

do you have console errors enabled

elfin isle
#

yes

obsidian plaza
#

fix those errors cause it might stop other code from executing no?

#

like if u call a function after the error

frail hawk
#

how comes it doesnt show you any errors. did you actually put your script on any gameObject

elfin isle
#

no- i dont have errors right now but i have had them in the past

like if i write something stupid right now itll give me an error

elfin isle
balmy hearth
#

I am making a Multiplayer FPS Shooter but i get this error and i cant fix it

frail hawk
ivory bobcat
balmy hearth
#

Okay

elfin isle
untold shore
# obsidian plaza also brother just make a variable so u dont have to getcomponent so much

Hey, can I still do this if Im trying to change the other script? Basically, I have a variable in the other script, and just want this item to add it's value onto that. Do I just do

handValue = hand.GetComponent<CardValuesScript>().handValue;
handValue = handValue + cardValue;

Or do I have to do something else?
For context so you don't have to scroll, here's my current code:

 public void Start()
    {
        hand  = GameObject.Find("HandPosition");
       // handValue = hand.GetComponent<CardValuesScript>().handValue;
        
        AddCardImage();
        hand.GetComponent<CardValuesScript>().handValue = hand.GetComponent<CardValuesScript>().handValue + cardValue;
        Debug.Log($"CardValue " + cardValue);
        UISprite.sprite = cardSprite;
        handValueText.text = "HandValue: " + hand.GetComponent<CardValuesScript>().handValue.ToString();
    }
``` Thanks!
#

When I did do it though, it wouldn't change the handValue, that's why Im asking.

ivory bobcat
scarlet hull
#

text kinda looks low quality any fixes?

frail hawk
cosmic dagger
short hazel
scarlet hull
short hazel
#

Indeed

#

TMP is better and replaces legacy entirely with minimal code changes to apply: change Text into TMP_Text and add using TMPro; at the top

untold shore
scarlet hull
#

i swiched to textmeshpro anything more i need to do?

elfin isle
cosmic dagger
scarlet hull
short hazel
#

Replace all legacy text with their TMP counterpart

#

You'll need to create a font asset if you want your old font

scarlet hull
scarlet hull
frail hawk
#

if(Physics.Raycast(transform.position, direction, out RaycastHit hitInfo, InteractRange, _mask))

cosmic dagger
short hazel
# scarlet hull i have font i want to use imported

Right-click the font in your Assets, and select Create > TextMeshPro > Font Asset. This will show an importer window, leave the settings as is or change them if you want, and confirm. This will create a Font Asset file along your original font file, you can then drag-drop it in the TMP Text on your object

elfin isle
frail hawk
#

not sure which direction you want to raycast , try transform.forward

elfin isle
#

or for each object i mean

frail hawk
#

did you create a new layermask in your inspector and then assigned it to your interactables

short hazel
#

Alternatively you can try without passing the layer mask in Raycast and see if it works again. If it does, then the mask is faulty

#

Also make sure the distance is big enough in the Inspector

elfin isle
#

and my interact range is at 100 r ight now lol

short hazel
#

You can use the Physics Debugger window to visualize the raycasts, or use Debug.DrawRay() to do that "manually'"

frail hawk
#

if your camera doesnt have a collider you could use what SPR2 said without using a lm

elfin isle
short hazel
#

Just don't put _mask in the argument list for your Raycast

elfin isle
short hazel
#

Then use the physics debugger to see where your ray originates from, and where it goes

#

(assuming "not working" as "no error, but raycast does not hit anything")

elfin isle
short hazel
#

There are plenty of resources online showing how to use the physics debugger

elfin isle
#

ykw yeah u right

#

would it be something like this?
Debug.DrawRay(transform.position, interactObj.transform.position);

short hazel
short hazel
#

The example you copied from this page works in your case because both do the same thing

#

Make sure you understand code you're copying

elfin isle
#

yes i do understand this
atleast i do now lmao

#

also

#

oh wait nvm i did smth stupid hold on

#

OH MY GOODDD A RAYY!!

cosmic dagger
#

gamedev, am i right?

short hazel
#

Good, now replace the * 10 in the code by * InteractRange and try again, just so the line adapts to the actual length of your raycast and not just 10

short hazel
#

So, is the ray originating in the right spot, and going in the right direction?

somber tulip
#

Anyone here know anything about gorilla tag fan games

short hazel
short hazel
elfin isle
#
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Rendering.Universal.Internal;

interface  IInteractable 
{
    public void Interact();
}
public class Interactor : MonoBehaviour
{

    public Transform InteractorSource;
    public float InteractRange;
    [SerializeField] LayerMask _mask;
    private void Update()
    {
        
        if (Input.GetKeyDown(KeyCode.E))
        {
            Ray r = new Ray(InteractorSource.position, InteractorSource.forward);
            if(Physics.Raycast(transform.position, transform.forward, out RaycastHit hitInfo, InteractRange)) 
            {
                Debug.Log("raycast hit");
                if (hitInfo.collider.gameObject.TryGetComponent(out IInteractable interactObj)) 
                {
                    interactObj.Interact();
                }
            }
        }
        Vector3 forward = transform.TransformDirection(Vector3.forward) * InteractRange;
        Debug.DrawRay(transform.position, forward, Color.green);
    }
}
short hazel
#

The line that says Ray r = ... can be removed as you're not using it

#

Then place a Debug.Log where this line was, just to make sure the code is running when you press E

elfin isle
elfin isle
#

ITS ALL WORKING NOW

#

WHAT

#

dude tysm

short hazel
#

Put the layer mask back in and you should be good

elfin isle
frail hawk
#

shaders 😉

#

orrr to make it realy simple, you could just change the material color.

elfin isle
frail hawk
#

no you can change the overlay color it would still visualy change but just recommended it.

spark sinew
#

hi y'all, I am trying to display a wireframe cylinder around a target person in AR (passthrough), however the cylinder in unity has too many wires in wireframe, is there a way to have something with less wires? Can I choose to reduce the number of displayed wires ?

finite patrol
#

how can I prevent this from happening?

elfin zinc
#

Hey so im trying go get visual studio to do code completion and it just wont for me. I looked online, i changed the external script editor to visual studio in tje preferences, i updatwd visual studio, and it still wont work. i dont know what to do and its making me very frustrated

frail hawk
#

!ide

eternal falconBOT
elfin zinc
frail hawk
#

close everything and restart 🤷‍♂️

elfin isle
frail hawk
#

use an else statement in your raycast

elfin isle
#

yes thats what i tried first but the "interactObj" doesen't exist in that context

#
        {
            if (hitInfo.collider.gameObject.TryGetComponent(out IInteractable interactObj)) 
            {
                interactObj.Interact();
            }
        } else {
            interactObj.UnInteract();
        }```
frail hawk
#

you can cache the object outside of the scope

elfin isle
frail hawk
#

i will leave that to you, don´t want to spoonfeed too much

#

you clearly lack of c# basics

elfin isle
#

i mean i ve been programming for what- 10 days?

frail hawk
#

when you say interactobj,Interact you save this thing outside ,the type is IInteractable

elfin isle
humble hound
#

hii can anyone guide me on how to use the input actions to create a visual script for player movement in 2d (platformer)

elfin isle
humble hound
humble hound
elfin isle
#

\

humble hound
#

lemme see if chatgpt can help

cosmic dagger
serene barn
#

isGrounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.5f, ground);

anyopne knows a better way of ground checking

verbal dome
#

Make the raycast originate from a bit higher so it can't start inside another collider (which it would not detect)

#

And make the distance so that it goes just a bit outside the player's collider

#

I prefer spherecasts though - they can't go thru small holes

serene barn
#

yes maybe spherecast will work better

verbal dome
#

Another way that some people do is to have a trigger collider at the bottom of your character and use OnTriggerEnter/Exit

#

I find that more fiddly

#

CheckSphere is an option too.

tired junco
#

Hey anyone knows where to get if this box is toggled (Custom Volume Component)?

verbal dome
tired junco
elfin zinc
verbal dome
#

When you toggle it

tired junco
verbal dome
#

Show how you log it

tired junco
#

keeps being true

verbal dome
#

What is the type of stack? I guess this is some newer API

#

Yeah it's a bit different from what i have used.. not sure right now

tired junco
#

all good thanks i changed to unity 6 yesterday i will have a look at it again

verbal dome
#

Could try logging the GetInstanceID of the effect before and after, just in case it actually disables it but swaps to another one...

#

I need to look more into how the VolumeStack works

serene barn
#

can someone help me i am using new inputsystem and would like to use crouching so when i press button it stays in crouching and when i pres again it goes back to normal what should i use in the new input system

short hazel
#

The standard button, and you handle the toggling logic in the code using a bool variable

humble hound
short hazel
#

Wild guess: make sure "Generate C# class" is check in the Input Actions Asset you're trying to use

humble hound
short hazel
#

Here is for C# questions, either wait or use C# instead :)

elfin zinc
short hazel
slender nymph
#

!ask

eternal falconBOT
slender nymph
#

use a better bin site than pastebin 👇 !code

eternal falconBOT
elfin zinc
open veldt
#

hello unity discord, if I want to check that this object is in front of another object in a collider, how would I do that :? Is there a method I can use?

slender nymph
#

depends on the actual use case. but the best option is likely going to be a physics query like a boxcast or overlapbox

open veldt
#

okay I'll look those up! Basically what I want to do is if it detects there's something in front of the object it's going towards, it will stop

slender nymph
#

yeah then a raycast or boxcast would likely be the way to go (or circle cast if you want it to match the circular shape), you'd have information such as how far in front of the object the obstacle is and other useful stuff that you might end up wanting to use

open veldt
#

Okay, thanks a bunch!

rocky canyon
#

if thats 2D... if its 3D just -2D from the method

#

but other methods are above ^

open veldt
#

Yeah It is 2D, I have those down, now I just want to check if there's a wall in front of the purple object in the collider so it can move around it, since once the purple object is in the collider it will go towards it

#

im gonna look up raycast and boxcast

rocky canyon
open veldt
#

Thank you! :D

compact stag
#

question, whats the best way to implement multiplayer on my game? i saw a tutorial using photon but i saw a devlog where the guy complained a lot about it, which one should i use??

swift crag
#

people are going to complain about every multiplayer system :p

slender nymph
#

the best is always going to be the one you've researched most thoroughly and aligns most closely with your plan for your project

wintry quarry
burnt river
compact stag
#

i see, its a more personal choice, alright, thank you guys!

#

ill take a look on the options and see theirs pros and cons, just looking for something small right now, like, 2-4 players at max

wintry quarry
#

Player count being just one of a hundred parameters

compact stag
timber tide
#

Netcode for gameobjects

cosmic dagger
#

try unity's new multiplayer solution . . .

fading mountain
#

hey guys. I am trying to code top down 2d movement in unity 6. I want the player to move with WASD and aim at the mouse. My code seems to work when standing still, however the aiming lags behind or does funky things when moveing or when the mouse is close to the player. I''m also getting terrible performance. Please take a look at the video. Here is my code as well:
https://pastecode.io/s/a9avmq6p

timber tide
#

Not seeing anything here that would create performance issues.

rocky canyon
#

id be curious as to what the build version does

night raptor
#

Definitely use the profiler to find out what’s causing the lag

fading mountain
#

hmm, ill build it right now and take a look. will probably take like 30 minutes though

edgy turtle
rocky canyon
#

👇 ..

#

Analysis**

#

you'll want to hunt for spikes*

#

click 'em use the Hiearchy to find anything thats taking considerably more time than the others

fading mountain
#

Looks like im running out of memory. Could just be that my laptop is very old.

robust condor
#

If I want a global variable, what is the recommended way? I dont want to query my gamemanager singleton to get the current game state for example.

cosmic dagger
robust condor
#

@cosmic dagger Ok that is the best way? Will it survive scene changes? Instead of having a dont destroy monobehaviour in the scene?

timber tide
#

just make it static

verbal dome
#

Static variables will persist when you load a new scene

cosmic dagger
fading mountain
#

Hey everyone, I am trying to code a simple 2d top down player movement script. Currently everything is functional but the movement is choppy in the editor and the build. Unfortunately I can't get a good video of it because my computer is too underpowered. Heres the code: https://hastebin.com/share/qevituqubu.csharp

slender nymph
#

i'm willing to bet that it's actually your camera's movement that is stuttering rather than the actual movement of the player

#

although you are breaking the interpolation of your rigidbody each frame

cosmic dagger
mystic lark
#

is there a way i can start the StartGame() method after the timeValue(my 3 second countdown) but only for one frame like in start but obuisly i cant do it in start after 3 sec?

verbal dome
#

Well, you can make Start into a coroutine

#

IEnumerator Start

mystic lark
#

and what would that do?

verbal dome
#

Or you can keep it as void and start a coroutine from within it

#

You can wait inside them

mystic lark
#

so i can wait 3 second okay let me check it out

mystic lark
verbal dome
#

Well, read the error

mystic lark
#

it seas that i might be missing a using directive and the type or namespace coud not be found

verbal dome
#

Yeah, use the quick tools in vscode to import the correct namespace

mystic lark
#

oh i did it

verbal dome
#

Click IEnumerator and then the bulb/cog icon or whatever

obsidian plaza
mystic lark
#

im so dubm

mystic lark
#

i tried it at first but id didnt work idk anyway thanks both

verbal dome
#

Because you do nothing after it

mystic lark
#

yea im still experimenting

mystic lark
trim gyro
#

could someone help me figure out why my UpdateLocationOwnedByIndexValueServerRpc() function does not work when run by a client? am new to using Unity's netcode for gameobjects 🙏

#

my function is run on a button which is clicked on by the client

#

it works for the host but not the client

slender nymph
eternal falconBOT
trim gyro
#

thanks

timber tide
#

Quite the method name

cosmic dagger
#

that's all i was looking at . . .

trim gyro
timber tide
# trim gyro 👍

lol dont worry I know the struggles. This is why I prefer underscore naming convention over camelcasing

#

also ServerRPC is legacy I think.

#

It's just RPC with different parameters

trim gyro
#

what do you mean?

timber tide
#

also I forget but you may need to inherit network mono

trim gyro
#

oh thanks

waxen adder
#

I have a question that is better asked via example code and its comments (look for PROBLEM AREA comments), so I'll plant those here and if additional information is needed, just let me know!
https://pastebin.com/g8yUhn3N https://pastebin.com/FgVuHLez

#

Thinking of doing delegates

violet crescent
#

hello! Im making a flappy bird game and i want the game to display a win screen when the score counter (ui text object) reaches a certain number (27). However, I'm not sure how to write code to make a certain action happen (if score = 27, show win screen) in c#. Could someone help me?

white girder
#

I was following a video tutorial on how to create a measurement tool through scripting and for some reason Unity doesnt let me add the text object into the field and its empty when I click on it. What am I missing?

using TMPro;

public class Measrement : MonoBehaviour{
    public GameObject pointA;
    public GameObject pointB;
    public TMP_Text text;

    void Start(){
       float distance = Vector3.Distance(pointA.transform.position, pointB.transform.position);
         text.text = distance.ToString();}
    void Update()
    {}}```
swift elbow
#

Drag the script onto an object in your scene, then drag your text object into that box

white girder
#

I see its working but it has a 0 now DIESOFCRINGE2 nvm had to reassign the objects

west radish
#

Quick tip, you can write text = $"{distance}" which turns it into a string

#

Another example $"This is {distance} long" to show the text in a practical way

#

Also by the way printing a float to text will often be 10 characters long as floats can have a lot of decimal places.

$" {distance:F2} " which will only show the first 2 decimal places

swift crag
#

more generally, this is called string interpolation

#

very useful!

white girder
shy coral
#

hey I need a little guidance, I'm trying to make it so that if I click on a sprite it changes color. I got the color to change on click, but it doesn't matter where I click lol, how do I make it only when it's on the sprite?

slender nymph
#

well right now you're just calling GetMouseDown every frame, then checking if the mouse button was clicked and if the GameObject you assigned in the inspector has a specific tag. consider using a physics query (like OverlapPoint) or use one of the event system interfaces for detecting clicks IPointerDownHandler

tawny grove
#

hey guys, i am having some trouble with RaycastAll, with it not detecting any colliders. The player does have a collider and the variable is assigned correctly.

tawny grove
#

that is what im trying to fix, it isnt detecting other objects/colliders infront of the player

#

found them on that one asset store for free, called monster pack or smthn

#

problem is
raycastall isnt detecting anything
while normal raycast only detects player

#

yeah, the grid has a tilemap collider while the player has a box collider

#

the little goblin also has a box collider

#

that makes a raycast downwards to detect ground right?

#

oh maybe, let me fix that

#

alright

#

nope 😔

#

oh that worked!

#

so this is good?

#

yeah

#

its for a detection system

#

whats the *5 do?

#

doesent the third paramater set the distance already?

#

lol

#

btw do you know why this is always detecting as hitting the player?

#

i see

#

that will be useful, but the problem is it is always detecting the player

#

like when it is out of the raycast line

#

not currently

#

oh you mean a tag

#

yeah i have that

#

ill look into it

#

okay i got it to work properly with tags 👍🏽 , ill probably use layermask for ground detection

#

thank you so much

#

this is just temp assets as i wait for some classmates sprites

#

im actually about to import some of them rn

#

they look great

#

ive tried godot but just couldnt get into it, albiet i was alot less experienced with coding

#

i think it was because i was still learning basics of c# but most godot tutorials was for g

#

ill try, thanks 🔥

upper forge
#

Can anyone help with build errors please?

slender nymph
north kiln
#

This is unnecessary to be clear, directions should be normalized and you already provide the length in the other parameter.

#

For something like DrawRay, it has no Length parameter so the direction isn't normalized

#

and it's necessary to scale it to whatever length is relevant

analog elbow
#

For a raycast to register a hit, the target object just needs to have a collider of sorts correct?

north kiln
#

Of course

magic panther
#

How hard did I mess up by CTRL+R*2-ing a class name

feral moon
#

Why don't all objects have null properties in the Inspector when creating a new project, but when project already created - they have null properties in Inspector?

sturdy wren
#

why doesn't the healthbar of my bunker change?

#

it can take damage but the bar stays full

cosmic dagger
#

fillAmount is a float: a decimal value. you need to get the result as a float . . .

sturdy wren
#

it still doesn't work even as a float

cosmic dagger
#

how did you change it?

sturdy wren
#

change the two int's in both scripts to float

cosmic dagger
#

what values are you using? place a log inside of UpdateHealthBar to see what results you get . . .

echo ruin
cosmic dagger
#

true, it does not update during runtime, but i thought they were having issues at the start of it . . .

echo ruin
#

They say it can take damage but bar is still full

#

Which makes sense if the bar is only updated at the start

#

So put UpdateHealthBar() inside TakeDamage() if that’s the method you use

cosmic dagger
ivory breach
#

Not sure if this is related to UI or code, but I got a problem where my UI elements are never positioned properly in any resolution but one when I'm using a piece of code that make the elements follow the player

#

The elements are placed in a camera screen space canvas btw

sturdy wren
#

didn't work

cosmic dagger
#

you need to call the method every time the health changes to update the health bar . . .

echo ruin
# sturdy wren i did that earlier

No, I’m saying that you put the UpdateHealthbar method in the void start(), which only updates when the object is loaded. Either put it in void Update(), or better yet, in the TakeDamage() method

cosmic dagger
cosmic dagger
# sturdy wren

you're decreasing healthBunker and using that as the maxHealth value. wouldn't that be the currentHealth value? i'm not sure why you place the max health before the current health in your parameters . . .

#

shouldn't you decrease currentHealthBunker instead . . .

echo ruin
#

Where are you using the TaleDamage method?

sturdy wren
#

got mixed up

#

but i switched them around and it still didn't work

cosmic dagger
cosmic dagger
sturdy wren
#

no before

cosmic dagger
#

we need after. it should be 1 before because your health is full . . .

sturdy wren
#

but the debug log says object for some reason

cosmic dagger
#

not sure what you mean . . .

sturdy wren
cosmic dagger
# sturdy wren

also, you only need to log HealthbarSprite.fillAmount. matter of fact, just do . . .

Debug.Log($"Percentage: <color=cyan>{HealthbarSprite.fillAmount}</color> | Current: <color=cyan>{currentHealth}</color> | Max: <color=cyan>{maxHealth}</color>");```
cosmic dagger
sturdy wren
#

i can't put it in the take damge script since the healthbar is on a seperate script

cosmic dagger
#

huh, just place this log in UpdateHealthBar after fillAmount is assigned . . .

sturdy wren
#

yeah it registered the numbers just fine

cosmic dagger
# sturdy wren

cool, but this isn't after taking damage. that's the log we're waiting for (to see if it works), not at the start . . .

sturdy wren
#

the bunker health does go down

#

i see it in the inspector

#

but the bar remains unaffected

cosmic dagger
#

then you need to make sure you referenced the correct health bar . . .

sturdy wren
#

i did

tawny grove
#

anyone know why my drawline doesent track properly? my actual raycast works fine now, just annoyed that the drawline isnt

cosmic dagger
# sturdy wren i did

in the inspector, set the fillAmount for the sprite to 0. test and see if it fills to 1 (because it's set to 1 at the beginning) . . .

tawny grove
sturdy wren
#

i set it to 0 and started the game and it became 1

cosmic dagger
# sturdy wren it does

i don't see what isn't working. i haven't seen an updated log where the current health is lower than the max health and the correct percentage is displayed (along with the health bar image from the game) . . .

north kiln
#

I missed you fixing it, sorry

eager spindle
#

which hand

#

which joystick

#

could you tell us more about your scene, code and how everything is set up

#

no

#

send it here

#

@queen adder

#

I might not be here all the time, there are others who can help you

#

👍

verbal dome
#

Yeah use a paste site for code

verbal dome
#

Can you rephrase your question? What is the current issue

digital cave
#

I’m about to lose my mind! (Beginner here) I'm trying to get data from an InputField, but it doesn't update unless I edit the prefab itself and override it before starting the game. I'm trying to update the value, but nothing seems to work. Can someone please help me figure out what the issue is?

using UnityEngine;
using System.Collections.Generic;

public class ProductUI : MonoBehaviour
{
    [SerializeField] private List<ProductData> productData;
    

    public void PurchaseProduct(int indexID)
    {
        ProductData selectedProduct = productData[indexID];
        
        if (selectedProduct.inputField == null)
        {
            Debug.LogError("InputField is not assigned in ProductData!");
            return;
        }
        
        selectedProduct.UpdateInputField();

        Vector3 spawnPos = new Vector3(0f, 1f, 0f);
        int totalPrice = selectedProduct.buyPrice * selectedProduct.amountToPurchase;
        MoneyManager.Instance.SpendMoney(totalPrice);

        Debug.Log($"{selectedProduct.name} purchased - {selectedProduct.amountToPurchase} times for ${totalPrice}.");

        for (int i = 0; i < selectedProduct.amountToPurchase; i++)
        {
            Instantiate(selectedProduct.productObject, spawnPos, Quaternion.identity);
        }
    }
}
#
using TMPro;
using UnityEngine;

[CreateAssetMenu(fileName = "ProductData", menuName = "ScriptableObjects/ProductData", order = 2)]
public class ProductData : ScriptableObject
{
    [Header("Product Data")]
    [Tooltip("Index ID for a product: Ensure that there are no duplicate numbers.")]
    [SerializeField]public int indexID;
    [Tooltip("Product name.")]
    [SerializeField]public string productName;
    [Tooltip("Product description.")]
    [SerializeField]public int productAmount;
    [Tooltip("Product purchase price by the player.")]
    [SerializeField]public int buyPrice;
    [Tooltip("Product sell price to the AI.")]
    [SerializeField]public int sellPrice;
    [Tooltip("Prefab of the product.")]
    [SerializeField]public GameObject productObject;
    [Tooltip("InputField of the product.")]
    [SerializeField]public TMP_InputField inputField;

    [HideInInspector] public int amountToPurchase;
    
    public void UpdateInputField()
    {
        string inputNumber = inputField.text;
        
        if (int.TryParse(inputNumber, out amountToPurchase) && amountToPurchase >= 1)
        {
            inputNumber = inputField.text;
            amountToPurchase = int.Parse(inputField.text);
        }
    }
}```
burnt vapor
jaunty yarrow
#

ok so i have a question on how to format scripts in the editor.

i have this script:
`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class uiManage : MonoBehaviour
{

//player 1
public Sprite p1Trump;
public Sprite p1Kim;
public Sprite p1Joe;
public Sprite p1Mette;

//player 2
public Sprite p2Trump;
public Sprite p2Kim;
public Sprite p2Joe;
public Sprite p2Mette;

//Canvas

public Image p1Image;
public Image p2Image;    
public TextMeshProUGUI p1Name;
public TextMeshProUGUI p2Name;

public void SetP1(Sprite sprite, string name)
{
    p1Image.sprite = sprite;
    p1Name.text = name;
}

}
`

the only problem is it looks like this in the editor:

#

is there any way to space certain sections out by a line or two?, or add headers, like in google docs

short hazel
#

Yes using attributes you put on the fields

verbal dome
#

There's also Header attribute if you want that

short hazel
#
[Header("Sample")]
private int Value1;

[Space(10)]
private int Value2;
jaunty yarrow
#

thanks alot

brittle maple
#

!code

eternal falconBOT
brittle maple
#

Ok well 3D movement keeps giving headaches, for some reason when I try to normalize my Vector3 (for movement), It either doesn't work (doesn't normalize it) or it makes all movement (including Gravity) slow and sluggish. https://paste.ofcode.org/x7HEVAHNF6WvkcbwNgv5ws ( In this code nothing is Normalized since I want someone to tell me WHAT to normalize)

jaunty yarrow
#

when you normalize it, max values become 1

#

so by setting your velocity to your totalmovement variable, you basically clamp the velocity to 1

#

why arent you using something like AddForce? does the movement need to be stiff?

brittle maple
verbal dome
#

FYI, this line transform.rotation = ...
breaks your rigidbody's interpolation because you are directly modifying transform

#

If you even have interpolation enabled (you should, it smooths the difference of rendering vs. physics updates)

jaunty yarrow
verbal dome
#

Start with changing from GetAxis to GetAxisRaw

#

GetAxis has some smoothing applied to it by default

#

GetAxisRaw bypasses that

brittle maple
#

Makes customizing movement easier?

verbal dome
#

Idk, you are mentioning stuff like "sluggish" so now i am confused what your problem is

brittle maple
#

You said something about "breaking interpolation", I should look into that?

verbal dome
#

Yeah, use rigidbody.MoveRotation instead of modifying transform.rotation directly

#

Modifying a transform when it has a rigidbody is bad. The physics system doesn't get properly notified about the change so it leads into bad collisions, broken interpolation and other glitchy stuff

#

When interpolation is not working, your character movement usually appears jittery

brittle maple
verbal dome
#

You are already using quaternions!

#

playerOrientation.transform.rotation is one

brittle maple
verbal dome
#

Yes. You can easily check if you just hover over rotation in your IDE:

#

Or when typing it

brittle maple
#

Yeah I got it, thanks, I guess that helps, but I still can't normalize Dx

verbal dome
#

Normalize what?

brittle maple
#

For some reason when I try to normalize my Vector3 (for movement), It either doesn't work (doesn't normalize it) or it makes all movement (including Gravity) slow and sluggish.

junior ether
#

Is using scriptable objects for making enemies with stats system a good approach?

verbal dome
#

You don't want to do that

swift crag
#

Normalizing a vector sets its magnitude to exactly 1. Do you actually want to do that?

verbal dome
#

In any case you should show the code that you tried

brittle maple
verbal dome
#

Do you want to normalize it or just limit your speed?

swift crag
brittle maple
verbal dome
#

Limiting it would only make it 1.0 if it is over 1.0

#

Like Vector3.ClampMagnitude

junior ether
#

I want to make like a stats system for my player and for the enemies too but I have no idea how to approach this

swift crag
#
  • You are mixing together player input and other sources of velocity
  • You are normalizing player input, which will make things like joystick input misbehave
verbal dome
swift crag
#

tbh, just start with a dumb bag of stats

#

give everyone a Stats object

verbal dome
#

Keep the y velocity out of the equation when you limit the move dir

swift crag
#
[System.Serializable]
public class Stats {
  public int strength;
  public int dexterity;
}

e.g.

brittle maple
junior ether
swift crag
#

well, you have to define what "works" means :p

#

What are "stats", anyway?

brittle maple
swift crag
#

Does every entity in your game have the same set of stats? Can you gain new kinds of stats over time?

#

That would require something more complex

junior ether
#

but like the player will hava a set of stats and enemies a different set of stats

swift crag
#

you should multiply moveSpeed in after clamping the magnitude of the input vector

verbal dome
verbal dome
swift crag
#

e.g. you're getting only 0.5 when you hold the D key

brittle maple
swift crag
#

I wouldn't expect that to happen

#

So fix the formula first. Consider logging the individual axis inputs as well as the combined vector.

#

That'll make it very clear if something is wrong

junior ether
swift crag
#

Do you mean that the player will have stats that enemies don't, and vice-versa?

junior ether
#

yes

swift crag
#

there are a couple of ways to do that

#

one would to give everyone the same set of stats, and to ignore anything that's 0

#

You could create two different classes for the two kinds of stat blocks, but that would result in a lot of duplicate work

#

since you'd need to write code to handle attacking a player vs. attacking an enemy

#

That's a big reason I prefer to make everyone "equal" nowadays. I don't have a Player class and a Monster class; I just have an Entity class

junior ether
#

would this work?

brittle maple
#

Ok well thank you for helping me guys!!! this movement looks very stiff, so I will look into "addForce" but Im 90% that its gonna be way too floppy.

reef swallow
#

!docs

eternal falconBOT
reef swallow
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

wise bloom
#

Yo idk if this is code but my camera wont work in unity for some reason

frail wind
#

guy can you help me?
so basically I wanted to make the player gun stop shooting when player died. But the thing is it on the other script; so i use the bulletSpawner = GameObject.FindGameObjectWithTag("Spawner").GetComponent<BulletSpawner>(); on the player script, to find a way to make these two script commutate with each other. After that i make a bool one for player private bool gunCheckList = true; and aother for the gun public bool gunCanShoot = true;. Then on player script void update i put this code in if (gunCheckList == false) { bulletSpawner.gunCanShoot = false; } which will disable the gun form shooting after player death, But instead i got an error, a Null error on line 40 which is bulletSpawner.gunCanShoot = false;.It say "NullReferenceException: Object reference not set to an instance of an object
CubeBeActing.Update () (at Assets/script/CubeBeActing.cs:40)''. what should i do?

languid spire
#

which basically means that this line

bulletSpawner = GameObject.FindGameObjectWithTag("Spawner").GetComponent<BulletSpawner>();

is not working and by a series of simple logical deduction it means the Spawner object found does not have a BulletSpawner component

frail wind
#

maybe because on the Gun since i only give the Spawner tag for the gun head which is parented by empty gameObject gun, and not the whole thing

wise bloom
#

I need help with splines

swift crag
swift crag
#

If the player only ever has one gun, this is trivial

frail wind
wise bloom
#

Does anyone know how to make an object Accelorate and decelerate on a spline and to be able to control it?

swift crag
#

i.e. how far along the spline you are

#

You can use that to calculate a world position

wise bloom
wise bloom
#

Or could you?

swift crag
#

There are two SplineContainer methods that you'll want to use

wise bloom
#

alr?

swift crag
#

Imagine the spline is 20 meters long and you want to position yourself 5 meters along the spline

#

5 / 20 = 0.25

#

Pass that to EvaluatePosition to get a position

#

If you move one meter forward, now you get 6 / 20 = 0.3

#

So this is a lot like moving in just one direction, back and forth

#

but you use the spline to turn that into a more complicated shape

#

Also, if you need to rotate the player, you can ask the spline for a tangent vector (pointing along the spline) and an up vector (pointing out of the spline)

#

That's enough information to figure out how to position and rotate something

obsidian plaza
obsidian plaza
#

basically saying that ur question is simple

junior ether
#

and like how do I apply the stats to the player and to the enemies?

obsidian plaza
#

if stats are just integers

obsidian plaza
#

like whats the stats and game

junior ether
#

stats are like health, maxhealth , range etc

obsidian plaza
#

it mostly just be math depending on what ur doing

#

changing health would change the healthbar scale and u die when it hits 0

junior ether
#

buy how do i make the player has its on stats and each enemy to have its own stats

obsidian plaza
#

ah

#

make a script that every enemy and player has

#

if these stats are shared by enemies

#

then u can change the values of each stat on each prefab however u want

junior ether
#

ok so just make a script that adds stats on the prefab then each enemie when spawned will have the stats

#

and the player too

obsidian plaza
#

more like make a script with stats that are all 0

#

then change the stats for each enemy type and player

#

but yea if thats what u meant

junior ether
#

yes

#

but how to reference

obsidian plaza
#

wdym

#

how to use it in other scripts?

junior ether
#

what

#

i made this

#
[System.Serializable]
public class Stats
{
    public int health = 0;
    public int maxHealth = 0;
    public float rang = 0;
    public float runSpeed = 0;
}
obsidian plaza
#

you dont need to = 0 and you dont need the system.serializable

#

looks good other than that

junior ether
obsidian plaza
#

you do “public Stats stats;”

#

then you can do stats.health for example

junior ether
#

oh oke

#

i get it

#

thx man

obsidian plaza
#

ofc

junior ether
# obsidian plaza then you can do stats.health for example

i tried this

public class PlayerStatsHandler : MonoBehaviour
{
    public Stats stats;
    private void Awake()
    {
        Debug.Log(stats.health);
    }
}

and it gives me this error
NullReferenceException: Object reference not set to an instance of an object
PlayerStatsHandler.Awake () (at Assets/Scripts/Player/PlayerStatsHandler.cs:8)

#

i dont understand why

languid spire
#

yes, stats is null, you do not initialize it

junior ether
#

so if i say stats.health = 100; will it work?

languid spire
#

no

#

you need to initialze the Stats class with new

obsidian plaza
#

if it was serialized

#

i guess they could do it that way

languid spire
#

yes, but it is not

junior ether
#
public class Stats
{
    public int health;
    public int maxHealth;
    public float range;
    public float runSpeed;
}
languid spire
#

he was told to remove that

junior ether
#

this is stats

obsidian plaza
#

just easier

languid spire
obsidian plaza
#

o lol true didnt notice that

junior ether
#

so what

obsidian plaza
#

u just need to do that for other script

junior ether
#

yes

#

for stats?

obsidian plaza
#

yea

#

then attach it to your prefab or player then fill the Stats variable on the player script

junior ether
#

ight

junior ether
obsidian plaza
#

without monobehavior?

junior ether
#

yes

obsidian plaza
#

its nice for things that are static for example game data. You can check if the player has beaten a certain enemy from any script

#

but the stats are different for different things so u would need to make a new stats in the script every time if u didnt have monobehavior

#

so this way is easier i think personally

junior ether
#

yes this is easier

obsidian plaza
hybrid prairie
#

anyone could teach me how to make a player sprint script where the sprint eases into the max speed instead of reaching the max speed instantly, thanks

swift crag
#

or Mathf.MoveTowards, perhaps, if you want to steadily approach a target value

hybrid prairie
#

i see thank you guys

polar ginkgo
#

I have been trying to set up VSCode with Unity for nearly the whole day and the "C# Dev Kit" extension has a little popup saying "The active document is not part of the open workspace. Not all language features will be available." where it prompts me to insert a solution. Except unity doesn't use a traditional solution (like .sln and .csproj) and I can't simply open the file and get Unity stuff because Unity depends on the C# Dev Kit extension. How can I make the Unity extension working without needing a solution file?

languid spire
polar ginkgo
languid spire
#

in your project folder

polar ginkgo
#

no .sln or .csproj in sight

languid spire
#

don't know which app you are using to display that but I can assure you they are there

polar ginkgo
#

Thunar file manager

#

hidden files are set to be shown

languid spire
polar ginkgo
#

on windows the default code editor is VS, right?

languid spire
#

yes, but the folder setup and contents are identical on all platforms

polar ginkgo
#

then how do I not have the .sln file

languid spire
#

only you can answer that one

polar ginkgo
#

I will create a new project just to see if you're right

languid spire
#

Maybe use a different file manager

polar ginkgo
#

They're both representing the same damn files

#

I can use the Dolphin file manager if that's that much of an issue

languid spire
#

I use Nautilus for Linux OS's

polar ginkgo
#

brand new Unity Project

languid spire
#

So that looks like it is only showing folders not folders and files

polar ginkgo
#

false, here's the Assets folder

robust condor
#

You got the visual studio editor package installed?

polar ginkgo
#

visual studio code does

languid spire
#

In Unity the Visual Studio package is used for both

robust condor
#

I think the package generates those files

languid spire
#

the VS Code package is depreciated

robust condor
polar ginkgo
#

WHEEEEEEEREEEE

#

(near the bottom are just language packs and documentation)

robust condor
languid spire
#

Package Manager and WHY IN GODS NAME are you using 6.1. Alpha if you don't know what you are doing

polar ginkgo
#

and I dont want to use an outdated version

languid spire
#

6.0 does work on Linux, there are thousands using it

polar ginkgo
#

it doesn't for me but that's a seperate issue

robust condor
#

Preferences > External Tools

polar ginkgo
polar ginkgo
robust condor
#

Window > Package Manager

languid spire
# polar ginkgo thank you

Be warned, extremely experienced Unity devs only use Alpha release when dragged screaming and kicking to do so, On Linux even more so

polar ginkgo
robust condor
#

And its selected in external tools and you hit regenerate?

polar ginkgo
#

in external tools I only have the option to browse for the text and/or image editor

#

which I did browse for VSCode

#

I think I might have an idea

robust condor
#

So select visual studio code then

#

Not open by file extension

polar ginkgo
#

I think I might know what's going on

robust condor
#

That is a dropdown

polar ginkgo
robust condor
#

So it's not finding your vscode?

polar ginkgo
#

why does it only generate the .csproj when using VSCode

#

can't it just generate them during project creation so there is no confusion

#

I was using a modified version of VSCode which it couldn't detect, a quick install of the actual VSCode and it works and I can generate the .csproj

polar ginkgo
#

already solved it, unity couldnt find the modified VSCode

#

Thank you so much for helping me with this

robust condor
#

It created the solution file?

polar ginkgo
#

the .csproj but I think it works

#

will check when the extensions decide to cooperate

robust condor
#

I think you can also try Assets > Open C# Project

polar ginkgo
robust condor
#

Okay nice

polar ginkgo
#

Thank you so much, I thought my VSCode extensions were wrong or sum.

#

Is it possible to generate the csproj file without the default text editor being VSCode?

robust condor
#

Donno

polar ginkgo
#

How many times should I regenerate my .csproj files?

robust condor
#

Prob once

polar ginkgo
#

Then I can just change the editor after generating it, thank you again and I think I will head out

robust condor
#

Unity creates multiple csproj files I think when you install packages and what not, because I have like 5+

spark sinew
#

hi y'all, how do I set the position of a cube in Unity? I tried to use this: targetObjCoord.x = (float)X1t;
targetObjCoord.z = (float)Z1t;

#

but it would not work

#

(I want to set the x and z coordinates to X1t and Z1t

wintry quarry
#
theObject.transform.position = whatever;```
spark sinew
#

thanks!

#

so for example could I do theObject.transform.position.x = whatever; for each coordinate? or do I have to create a vector first ?

wintry quarry
#

you should make a vector

#

and assign it

spark sinew
#

ok thanks

obsidian plaza
fiery carbon
regal marlin
#

I need a hand with raycasting issue.
I've placed 2 cameras, 1 is main for player, 2nd is it's child, in attempt to fix the issue i have with the test.
Before applying a canvas to make the project look more pixelated i was able to click anywhere on the surface and my green bean would gladly walk there. Now all I get is just that raycast did not hit the ground. I've no idea what to do.

It is generally a blank project so if anyone needs i can just upload entire project

green flame
#

Hello! I tried many method to set the parent of an Instance but 0 success.. Someone can explain me why this:

        gameObject = UnityEngine.Object.Instantiate(weaponPrefab, new Vector2(0, 0), Quaternion.identity);
        gameObject.parent.transform = character.transform;

Is not working please ^^ ? (I tried with parent, with gameObject.GetComponent etc.. But nothing works :/

prime goblet
obsidian plaza
#

replace with a gameobject

green flame
wintry quarry
wintry quarry
obsidian plaza
#

transform doesnt have to do with parenting

wintry quarry
#

yes it does

#

the code is simply wrong

obsidian plaza
#

i mean not setting it

prime goblet
wintry quarry
wintry quarry
green flame
#

Object reference not set to an instance of an object
With:

gameObject = UnityEngine.Object.Instantiate(weaponPrefab, character.transform, Quaternion.identity);
gameObject.transform.parent = character.transform;

Is this wrong then ?

rocky canyon
#

should u be using gameObject as a variable name?

wintry quarry
#

also pretty sure that code wouldn't even compile

wintry quarry
green flame
#
        gameObject = UnityEngine.Object.Instantiate(weaponPrefab, new Vector2(0, 0), Quaternion.identity);
        gameObject.transform.parent = player.gameManager.Character.transform;

Error on the second line ^^

fiery carbon
wintry quarry
#

figure out which one

#

and fix it

regal marlin
#

^ player move, isometric camera setting, and movement with left click

#

IDK tho how that is related to raycast which is a togglable in canvas

wintry quarry
# regal marlin

Since you're using Camera.main, make sure you only have one camera tagged MainCamera and that it's the correct one.

wintry quarry
#

the canvas is not relevant

rocky canyon
#

Raycast Target is what i think ur thinkin of about the canvas

regal marlin
#

I have Main Camera, it has child objects RaycastCamera, and within it, Camera.

I get mostly did not hit ground, only in very lower part of the display screen, it manages to make occasional hits but then the bean is not going where its supposed to at all

wintry quarry
#

is it the correct one

#

what are the tags of the two cameras

#

why are there two cameras

green flame
rocky canyon
#

yeap

wintry quarry
regal marlin
# wintry quarry Which one is the main one

MainCamera is the main one
I have a canvas with a texture, it ended up blocking completely my movement so i made 2nd camera as a child, with disabled camera feature, to only do the culling

rocky canyon
#

but sometimes it can be the line after

wintry quarry
green flame
#

Ty boys for ur help ❤️

regal marlin
wintry quarry
#

so it's really not clear which one is the "real" one

#

But that third one would be the one that's affected by a canvas

#

so you need to be more specific about which specific script is not working and what's going wrong with it.

#

You also should clean up your project and get rid of unused scripts which are probably causing confusion

regal marlin
#

For now I have:

  • Deleted the 2nd camera so I only have 1
  • From the EventSystem I have removed the script responsible for movement

Now half of screen works but bean always travels to the right and never stops

wintry quarry
#

Continue debugging your code.

#

You have PlayerMovement and SimpleClickToMove scripts still. Why still two movement scripts?

#

Also the SimpleClickToMove you put on the EventSystem GameObject? I suspect you are not actually using that script.

fiery carbon
#

I don't understand why it isn't working

wintry quarry
regal marlin
#

i only have 2 scripts in my project, 1 for isometric view, 1 for movement

fiery carbon
regal marlin
#

i dont understand why the character only responds to click when i click lower half of the display, but never when i click the higher half. And why it only travels in one direction (right) and never anything else.

And when I remove the Canvas, it magically works as intended.

wintry quarry
wintry quarry
regal marlin
fiery carbon
wintry quarry
wintry quarry
fiery carbon
wintry quarry
#

What else is on the prefab

fiery carbon
#

Just a light source and a model mesh

wintry quarry
#

Show the inspector? Make sure it's the actual prefab and not an instance in the scene

#

Also make sure your console window is always open in Unity (it wasn't in your video) so you can see any errors or warnings.

fiery carbon
#

Earlier I tried to make my map generation script play the audio clip manually after instantiation but it still gave the same result

fiery carbon
#

Just this

#

Took a look at the profiler and there doesn't seem to be any issues there either

#

What's weird is that whenever the game window is unfocused, the sound starts playing normally

#

This led me to conclude that, for whatever reason, something is resetting the audio clip's playback after each frame

wintry quarry
#

Yes

#

it certainly seems so

#

Most likely one of your scripts

regal marlin
#

back to normal boring display

fiery carbon
#

Nothing seems out of the ordinary to me here

tawny grove
#

Im gonna start attempting to make a pathfinding algorithm, and i was wondering if there was any way to use raycast to find where it stops touching something

#

Like if it started in a collider with the ground tag

#

Thenpoint where it is no longer touching that

autumn stream
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

fiery carbon
#

I might've actually discovered something

#

So apparently, SetActive is being run on every map chunk, every frame

#

That's what's causing the audio to repeat

#

This was such a stupidly easy fix

tender wren
#

I have a quick question someone might have an answer to.

I was working on my project and decided to connect to unity version control, it appeared to work, but I didn't push any changes.

My unity project closed and I could not open it anymore. After, the project folder is missing all assets and the scripts were all removed.

No my code editor shows this kind of thing:

I tried to download the project via the version control and it is empty with no assets. Is the project recoverable? Has anyone seen this before?

queen adder
#

hey guys

#

my script have a problem, i make a level platformer game

#

the player needs get a key to open a door

#

and his game to find the key u need go in secrets passes

#

and when u touch in the secret pass the level show this

#

and when u have the key u can open the door and go to the next level using a teleport, the variable detect teleport is HasTeleported, and the wrong script is ResetVar, this reset all variables to need teleport, open secrets passes and more. And when I go to Level 4 the variable isCollidingWithPlayer responsible for detect if player find the secret pass doesnt working and stay to True(isCollidingWithPlayer are a bool)

wintry quarry
# fiery carbon

Looks like you're calling roomParent.SetActive(visible); every frame

#

Which will probably restart the audio

#

seems like a bad idea to deactivate and reactivate the rooms every frame

fiery carbon
#

I decided to change the instantiation parent to worldGrid

#

So nothing gets deactivated

fiery carbon
#

Albeit the implementation is a bit dodgy

wintry quarry
fiery carbon
#

Yeah

hearty trout
#

it wrote in what you wrote, preatorblue.

placid oxide
#

I've been making a game that has very large numbers. What is the best method to keep transforming all numbers in a shorter form so that c# can do calculations?

wise aspen
#

could someone help? i just wanted to do game for my friends

earnest wind
#

is this okay code? or will this create too many instances for the garbage collector?

wintry quarry
# earnest wind

What does "too many instances for the garbage collector" mean?

earnest wind
wintry quarry
earnest wind
wintry quarry
#

then it's fine

earnest wind
#

okay

obsidian plaza
#

hv i not seen this screen in unity

wise aspen
#

its in disboard

#

but i fixed it

gentle herald
#

Yo I'm building a game and I add y axis movement and for some reason when I look up it moves me forwards and when I look down backwards

eternal stag
mint patrol
#

My character keeps falling through the floor that I placed in game. I added the collider but nothing is working

obsidian plaza
obsidian plaza
obsidian plaza
eternal stag
gentle herald
obsidian plaza
#

so there u go lol

obsidian plaza
eternal stag
obsidian plaza
gentle herald
obsidian plaza
gentle herald
eternal stag
#

first 2 are the cam changer part and third pic is camera object

obsidian plaza
#

its just the y camera movement?

gentle herald
#

Like I look up and moves me forward

obsidian plaza
#

it moves ur character forward

gentle herald
#

Yes, it moves the character forwards

obsidian plaza
#

what game is this where the mouse controls the characters

gentle herald
#

The mouse controls the camera like looking up and down

#

left and right

obsidian plaza
#

but u said it moves the character

gentle herald
#

Yeah bc it moves me forward and backwards, but its unwanted

obsidian plaza
eternal stag
#

imma try and see if it works

obsidian plaza
gentle herald
#

It is?

obsidian plaza
#

at the top no?

#

verticalInput = axis

gentle herald
#

Idk what I'm doing bro, I'm using perplexity

#

and the stupid ass ai can't fix it

obsidian plaza
#

is ur movement variable for the camera or player?

obsidian plaza
gentle herald
#

AI

#

The movement moves the camera

obsidian plaza
gentle herald
#

No

#

I'm just so fucking lost rn

obsidian plaza
#

ur good

gentle herald
#

I tried following the tutorial and didn't understand a single thing so I just decided to use AI

obsidian plaza
#

so the rigidbody is the camera?…

gentle herald
#

Yes

obsidian plaza
#

yea it is..

#

because it will take longer if u finish at all and u wont learn

#

so back at square one with no experience even if u succeed

gentle herald
#

Fair point

eternal stag
obsidian plaza
#

sick

#

gotchu

obsidian plaza
#

ur saying this script is on ur camera

#

im still confused

gentle herald
#

It is

obsidian plaza
#

so when u jump it moves ur camera

#

not character

#

is the character the camera

gentle herald
#

No, when I look up it moves the character forward

obsidian plaza
#

ur movement variable is depending on ur mouse movement

gentle herald
#

ok, how do I change it then

#

Cause I'm losing my shit