#💻┃code-beginner

1 messages · Page 151 of 1

edgy fox
north kiln
#

it pings the object in the hierarchy

edgy fox
#

I clicked on it and it didn't do anything

rocky canyon
#

wow, i just learned of this physics debugger, as well as the frame debugger, these tools are awesome

edgy fox
#

ik same

#

but where in the log do I click to highlight

rocky canyon
#

if u double click it it will automatically select it

edgy fox
#

it doesnt highlight it htough

#

wait im dumb

#

waiit no it doesnt

#

it works if I do a different gameObject but if I do Debug.Log("Click", hit.transform.gameObject) nothing happens

#

but if I just do Debug.Log("Click", gameObject) it highlights an object

#

but I only have 1 object named WallEZ so I know which one it is

native seal
#

anyone know how to fix The referenced script (Unknown) on this Behaviour is missing!

wintry quarry
native seal
#

its just popping up 4 times

queen adder
#

cursed UnityChanwow

wintry quarry
rich adder
#

are you sure its not the ones from saving/compiling scripts while in play mode?

wraith mango
#

why would it take in the transform to assign the new object a parent

#

sorry if that was worded badly

#

this is for instantiating, should've been more specific

timber tide
#

well, if you want to parent it on the hierarchy then you're free to do that, otherwise it'll just be in world space

wraith mango
#

i need it to instantiate as a child of another object

abstract pelican
#

Can you tell me why this doesn't work in the isometric world?

#

if I press W then it goes to the left

timber tide
#

well, then you give it the parent of the object you want to child it with

wraith mango
#

why is it a transform, and not a gameobject

timber tide
#

all gameobjects have a transform (if they exist in the scene, then they must have some type of coordinates in it)

#

it's just a unity thing

wraith mango
#

alr i just didn't think it made sense lol, i figured it would take a gameobject

abstract pelican
#

help guys

timber tide
#

you're right in a sense that it would make more sense to be a gameobject ref, but if you think about it more it is about placement in space (vector/rotation/matrix via local coordinates) which is more related to transform values

abstract pelican
wraith mango
abstract pelican
wraith mango
#

expensive

abstract pelican
#

who will help me with my problem?

wraith mango
#

your assigning the currentrunmovement.z to y

#

i could be wrong im just guessing

abstract pelican
#

and which one is needed?

#

I have a top-down camera, the character moves normally

#

but there is no isometry

wraith mango
#

you said your character is moving the wrong way

abstract pelican
#

Yes, that's right, he doesn't walk correctly in isometry

#

if I press W it goes to the left, if I press A it goes down

#

it turns out 90-degree turns, instead of 45

#

In theory, if I press W it should be 45 degrees

#

But instead I turn 90

tough lagoon
#

It doesn't look like you are coding it to go 45degrees. You are using a lookat and rotating that way

abstract pelican
#

how do I fix it in my code?

tough lagoon
#

transform.Rotate(new Vector3(45,0,0);

#

As for movement, you are using WASD as arrow keys. And applying the position of the arrow keys. Most isometric aren't left to right and up and down though. A tile based isometric you usually want left x2 and up x1 for example.

#

But you have the code on going left / right/ up / down. It's just a guess though as the input keys are using the newer input manager and would need to be verified there as well

#

Basically you need to take the input and adjust it for the view of your game

abstract pelican
#

like this?

tough lagoon
#

No, why are you adding a lookat?

#

If you want to rotate it 45 degrees, just do transform.Rotate(new Vector3(45,0,0));

#

Like, you can just rotate it 45 degrees without needing to add anything else

#

I'm not sure why it is doing a lookat etc.

#

But maybe it's needed? It would depend on the context of the rest of the project

rocky canyon
#

Why are my Debug.Log()s are so different? The left image is 2021.3, and the right image is 2022.3
I haven't changed any settings that I know of. The only difference is the first is a Windows project, and the other is a Mobile project.
Same code, same debug yet :

  • The 2021 Windows version is cleaner and I can double-click it to show the line in VSCommunity.
  • The 2022 Mobile version is cluttered (having the line number way down the stack. and a double-click does not open VSCommunity
abstract pelican
soft canyon
#

I'm making a custom editor for one of my scripts right now but the object assign box is super small when there is plenty of space between the label and box

This is my current code:

        dungeonGen2.distObject1 = (GameObject)EditorGUILayout.ObjectField("Object 1", dungeonGen2.distObject1, typeof(GameObject), true);
        dungeonGen2.distObject2 = (GameObject)EditorGUILayout.ObjectField("Object 2", dungeonGen2.distObject2, typeof(GameObject), true);
        EditorGUILayout.EndHorizontal();```

And ChatGPT is telling me to split each one into two lines to set the label size like this:
```EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Object 2", GUILayout.Width(70));
dungeonGen2.distObject2 = EditorGUILayout.ObjectField(dungeonGen2.distObject2, typeof(GameObject), true) as GameObject;
EditorGUILayout.EndHorizontal();```

Is there a way to set the size of the label and keep it all in one line per object-label pair? I tried just putting the GUILayout.Width(70) after "Object 1" and it didnt work
abstract pelican
#

If I do as you suggest

tough lagoon
abstract pelican
rocky canyon
#

im aware.. but thats all it is on this version

tough lagoon
rocky canyon
#

lol the mobile setup* just has SOOOO much stacktrace lol

tough lagoon
#

Is that in the editor view or while testing on device?

rocky canyon
#

its the editor..

tough lagoon
#

What version is that one?

rocky canyon
#

im just trying to figure out what the difference is exactly.. b/c the Big one.. doesn't open Visual Studio when i double click it.

#

like the smaller version does

#

the big one

#

and the small one

#

just strange.. unless the mobile setup uses different types of logs?

tough lagoon
#

Im not sure why the one on the right is showing a detailed stack trace. But it's not narrowing it down to code. I'm suspecting there is a debug option enabled somewhere for stack trace digging

rocky canyon
#

thats the only thing i can think of as i didnt really change anything besides from 1 line to 2 line

rocky canyon
north kiln
#

Go through the top right menu of the console window, or the player settings and set them to Script

rocky canyon
#

❤️ so much better

#

And the double click to open in VS works again!

#

not sure how that got flipped lol, TIL📝

north kiln
#

The setting for the window is annoyingly the same as for builds

rocky canyon
#

i didn't mind at first, until I started looking for line numbers.. had to scroll half a page to find the first script hyperlink looking thing

abstract pelican
#

How good is this solution?

north kiln
#

Why am I being pinged?

abstract pelican
#

so that the control is normal in 3d isometry

north kiln
#

what on earth does this have to do with me

abstract pelican
#

We've been talking to you, haven't we?

#

I can't see well, I have a disability, don't you get mad 😭

rocky canyon
# abstract pelican How good is this solution?

my two cents: if it works, roll with it. If there's an issue with it you'll discover it before too long,
and if it needs optimized in the future, that's a future project..

  • does it work ?
  • can you understand it ?
abstract pelican
rocky canyon
#

it cant be worse than polling for input.. which is what usually gets done

rocky canyon
#

open up the profiler, and check

abstract pelican
#

I don't understand what to use instead in the new version

abstract pelican
wintry quarry
rocky canyon
#

ahhh i miss rider 😦

#

no suggestions for me 😢

north kiln
#

if your Unity version has it as obsolete it should mention obsolete methods no matter the IDE, no?

abstract pelican
rocky canyon
#

not sure

north kiln
#

Also, Rider EAP just started, you can use it for free for a bit again

rocky canyon
#

brb! lol

abstract pelican
#

I use it for free

north kiln
#

the EAP just started yesterday

wraith mango
#

code: https://hastebin.com/share/ikibexemim.csharp

The problem is that there shouldn't be that space between "objectives" and "obtain one coin", then when i run the complete function it tries to replace the white space instead of obtain one coin

abstract pelican
north kiln
#

it says you have a subscription

rocky canyon
#

visual studio is ole' reliable.. always there when you need it most..
but rider, ❤️ me some rider.. like that new toy you don't need but looks great cruising around town in 😄

abstract pelican
#

I didn't even come in.

#

I activated the code that was sent to my email

#

I shared it with a friend, and he uses it too

north kiln
#

You got the license somehow—presumably by paying for it

rocky canyon
#

well, thats fortunate

#

student perks perhaps

north kiln
#

Maybe

abstract pelican
#

I can't physically buy it, my banks don't work.

north kiln
#

Are you using the github student developer pack then?

abstract pelican
#

no

rocky canyon
#

🏴‍☠️

abstract pelican
rocky canyon
#

lol jk with ya 😄

abstract pelican
#

I just downloaded it from the website and wrote to them

#

I get all the updates that come out without any nonsense

north kiln
#

and wrote to them?

rocky canyon
#

well, lucky you

#

yea, i need to email em too.. see if i can get a hook up with free liscense

abstract pelican
#

I was told that I can use it until the release of the 2024 version

#

after that, she will turn off

north kiln
#

Right, well I have no idea why you buried the lede

rich adder
north kiln
abstract pelican
#

can you tell me a good plugin to put the code in order?

rich adder
#

@rocky canyon this what I meant 🙂

edgy fox
#

so the conversation earlier just sort of ended... when I click on the debug message for Debug.Log("Click", hit.transform.gameObject); nothing gets highlighted

abstract pelican
#

so that he formats my code beautifully

north kiln
wraith mango
north kiln
north kiln
eternal falconBOT
edgy fox
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/* Script Purpose
 *  On Room Frame instantiation:
 *  add empty walls around them
 *  add actual walls where walls already are
 */
public class AddWalls : MonoBehaviour   //Called when new room frame is placed
{
    [SerializeField] GameObject wall, blank, cam, parObj;
    [SerializeField] BoxCollider linearOffset;
    [SerializeField] private LayerMask wallMask;
    /*
     * wall: the wall that will be added upon room creation
     * blank: empty gameObject
     * cam: the camera
     * parObj: parent object of the frame, holds all of the walls etc. as children
     * linearOffset: the box collider for the frame which determines its size
     * scriptHolder: an empty gameObject that holds many scripts used as a really shitty library
     */
    [SerializeField] float wallOffset;//percent of distance the wall is between the center of the frame and the edge of the frame
                                      //I could have done it by distance but for some reason I couldn't figure out how???

    //Called when new room frame is placed
    void Start()
    {
        gameObject.GetComponent<Renderer>().enabled = false;
        GenerateWalls(transform.gameObject);
        FindNeighbors();
        parObj.name = $"Room ({parObj.transform.position.x/6}, {parObj.transform.position.y/6}, {parObj.transform.position.z/6})";

    }
    
    void GenerateWalls(GameObject obj)//generates empty wall parents around a room on all sides except those adjacent to other rooms
    {

        for (var i = 0; i<= 3; i++) {
            Quaternion rotApplied = Quaternion.Euler(0, 90f * i, 0);//adds 90 degrees each iteration
            Quaternion rot = obj.transform.localRotation;//rotation of frame, applied to walls
            Vector3 framePos = obj.transform.position;//position of frame

            Vector3 offset = new(0,0,linearOffset.size.z * 0.5f);//offset from the center of the frame
            offset = rotApplied * offset * wallOffset;
            offset += framePos;
            GameObject newObj = Instantiate(blank, offset, rotApplied * rot, obj.transform.parent);
            newObj.name = $"{blank.name}{(NSEW)i}";//renames walls based on direc1tion they are facing
        }
    }
    private void FindNeighbors()//finds if there are neighboring frames
    {
        float sizeX = linearOffset.size.x * 0.5f + 2f;
        
        for (int i = 0;i<=3; i++)
        {
            //Debug.DrawRay(transform.position, Quaternion.AngleAxis(90f * i, Vector3.up) * Vector3.forward * sizeX, Color.red, 5f);
            if (Physics.Raycast(transform.position, Quaternion.AngleAxis(90f * i, Vector3.up) * Vector3.forward * sizeX, out RaycastHit hit, sizeX, wallMask))//shoots ray, rotates by 90 degrees per iteration
            {
                Debug.Log($"{Quaternion.AngleAxis(90f * i, Vector3.up) * Vector3.forward * sizeX} {90 * i}");
                Debug.Log($"Hit object {hit.transform.name}@{hit.transform.position} from {transform.position} with run index {i}", hit.transform.gameObject);
                Debug.Log("Click", hit.transform.gameObject);
                Debug.DrawLine(transform.position, hit.point, Color.red, 5f); 

            }
        }
    }
    private enum NSEW//pos Z = north, pos X = East
    {
        North, East, South, West
    }
}
#

FindNeighbors is where the issues are

wraith mango
#

code: https://hastebin.com/share/ikibexemim.csharp

The problem is that there shouldn't be that space between "objectives" and "obtain one coin", then when i run the complete function it tries to replace the white space instead of obtain one coin

abstract pelican
#

I do not know how many times it can be used

wraith mango
abstract pelican
north kiln
# edgy fox ```cs using System.Collections; using System.Collections.Generic; using UnityEng...

I can't see what the issue would be. Perhaps try to Debug.Break() when the issue occurs so it pauses, and then you can see the state of the scene at that point.
What is the name of the object it looks like it's hitting (when selected via the physics debugger overlay?) at that point in time...
Perhaps use the debugger instead of the logs to see if you can gleam any more info, like the hierarchy or something else

edgy fox
north kiln
#

Just by looking visually and using the Mouse Select option in the bottom right menu, selecting the object

edgy fox
#

there is no object there to select

#

its still just hitting nothing

north kiln
#

these screenshots are showing objects there though?

edgy fox
#

those objects are ignored via layermasking

north kiln
#

stop thinking about that for now

#

they are still things you should consider

edgy fox
#

its hitting BlankSouth

#

but logs say WallEZ

abstract pelican
#

can you tell me how to make steps for a character so that there is not a lot of sound of steps?

north kiln
edgy fox
#

that's the wall that has arrows here

#

if WallEZ there doesn't exist, this bug doesnt happen and it doesnt register as hitting anything

north kiln
#

and this one?

edgy fox
#

that;s the plane floating in tthe distance

#

top left of screen

north kiln
#

Can you disable the blank wall that it looks like it's hitting, and then advance the frame and look again?

edgy fox
#

right now, the bug happens if the cloned wallEZ exists there and doesn't if it isn't there

north kiln
#

Does the cloned wall get moved around at all?

edgy fox
#

like redo it with the blank wall disabled or disable and continue?

#

the cloned wall does not get moved after instantiation

north kiln
#

No, just checking if there's something there when you disable the one it's apparently hitting

edgy fox
#

yeah the code instantiates it prerotated and premoved

#
if (Physics.Raycast(hit.transform.position, hit.transform.rotation * new Vector3(0, -1f, 0f), out RaycastHit hitInfo, 0.5f, wallMask))
{
    Instantiate(newWall, hitInfo.transform.position, Quaternion.Euler(new Vector3(0, hitInfo.transform.eulerAngles.y, 0)), hitInfo.transform);
}```
#

that's the code that puts it there

#

with newWall being WallEZ

north kiln
#

Do any of the parents of WallEZ have a rigidbody?

edgy fox
#

there are no rigidbodies anywhere in the scene

north kiln
#

if this works it's probably not the solution you should go with, but it might fix it... can you add Physics.SyncTransforms before FindNeighbors?

edgy fox
#

still doesnt work

north kiln
#

I have no idea at this point. I think you'll have to upload your project somewhere to have someone else look at it unless someone else has an idea

edgy fox
#

dang thanks for trying

#

I'm completely stumped

spring skiff
#

can someone tell me what is wrong with this?

    private bool[] myArraybool = new bool[30];

I want to set a max. length directly in the script because I want to keep my Inspector clean.

gaunt ice
#

then recreate a new array and copy all stuff into it

#

or using some wrapper of an array ie list

spring skiff
gaunt ice
#

you already limit the length by setting the length

spring skiff
#

is my code not wrong?

#
    private bool[] MyBool = new bool[1];



    void Start()
    {
        print("MyBool 0 = " + MyBool[0]);
        print("MyBool 1 = " + MyBool[1]);
    }
gaunt ice
#

ofc you cant access the memory space with index >= array.length

spring skiff
#

what do you mean?

#

the last print is to make sure thaat it should not work.
but even if I outcomment it I still have this error.

#

its always confusing me when '0' does count and when not.

#

If I say bool[1], does this not mean the "0" is also counted?

gaunt ice
#

array index starts from 0

spring skiff
#

so whats wrong with the code up there?

spring skiff
gaunt ice
#

your array length is 1 and you try to access [1]

spring skiff
gaunt ice
#

and basic counting, for open interval [0,b) ie 0<=index<b the count is b-0 while for closed interval [0,b] ie 0<=idx<=b count is b-0+1
hence the valid range of index is [0,b)

spring skiff
#

ok thx.

gilded pumice
#

Hey all so I'm trying to get a chest to spawn random loot when opened. I have the following code to do this:

if (collision.gameObject.CompareTag("unlockbronze") && playerAttributes.bronzeKeysRemaining > 0)
{
playerAttributes.RemoveBronzeKey(1);
Instantiate(chestLootPrefabs[chestLootPrefabsIndex], collision.transform.position, collision.transform.rotation);
StartCoroutine(OpenChestDelay(collision.gameObject));

}

this does not throw an error, but it doesn't instantiate the loot either. If I remove the "collision" from the transform position and rotation, it works and instantiates the object on the player, which is obviously not what I want to have happen. I tried making a script and attaching it to the chest directly but it doesn't trigger since the chest is static (plus I'd prefer not to do it that way if I can help it). Any thoughts or help?

north kiln
gilded pumice
#

I didn't debug it, but the other parts of the code function as intended (the bronze key is deducted from inventory and the chest is destroyed after a delay)

#

so the code block is at least executing

north kiln
#

Because if it is, then it is instantiating the object. Perhaps just not where you think it is?

gilded pumice
#

well, nothing new appears in the hierarchy. I guess I'm wondering if the collision.transform.position is correct syntax, or if its doing something else (this was a complete guess on my part to try to change the spawn point from the player to the object the player collided with)

dim halo
#

hello guys

#

I want to download unity editor 2019

#

where can I download it from?

gilded pumice
sweet flume
#

Guys 1 question when I type using UnityEngine.SceneManagement sometimes it works sometimes it doesnt

slender nymph
#

show an instance of it not working

sweet flume
#

K 1 min

#

Sometimes it autofills

#

Sometimes it doesn't

#

It's sending

slender nymph
#

you need to configure your !IDE

eternal falconBOT
slender nymph
sweet flume
#

I don't have dc on my laptop

#

I'ma install it rq

timber tide
#

testing there doesn't seem to be a difference but with rotations like to lie to me

north kiln
#

I believe they normalize it, however that's not gonna be guaranteed if you use any other library

#

Quaternions from Unity methods are always normalized however

#

they are never going to be broken

fringe plover
#

does someone know how to make dropdown like here in my own script?

north kiln
#

The easiest thing would be to use an enum

fringe plover
#

okay

north kiln
fringe plover
#

oh thanks

supple needle
#

Here's the code im using for rotating the steering wheel in my car, i want it to rotate back to original position when i dont turn the vehicle though, any approaches i can take?

tawdry dome
#

Why when I click create a new palette and create a folder, nothing happens and I can't create a tile palette?
This is on 2D btw

buoyant prawn
#

ok so like probably a dumb question but what is the advantage of using TMPro components over like legacy text components, almost every Brick wall I have run into coding in unity so far (still early learning but you know) has had to do with TMPro and me not being able to find good info on how it works

hot sky
glossy eagle
#

how are those things called so I can create a window that does something later please? Like I only need the name, the rest I'll try to search it haha

buoyant prawn
#

thank you*

fickle plume
buoyant prawn
sweet flume
#

Just a question

#

When I press the play button on unity all the buttons I've placed dissapear

timber tide
#
if (incrementInfo.abilityCastAmount > 1)
{
    void SetIncrementRange(IncrementRangeTypes rangeType, in Vector3 a, in Vector3 b, ref Vector3 unitsPerIncrement)
    {
        if (continualCastData.IncrementData.IncrementRangeTypes.HasFlag(rangeType))
        {
            unitsPerIncrement = (b - a) / (incrementInfo.abilityCastAmount - 1);
        }
    }

    //Can't use ref keyword on other structs
    SetIncrementRange(IncrementRangeTypes.StartPosition,
            continualCastData.IncrementData.PositionIncrementA,
            continualCastData.IncrementData.PositionIncrementB,
        ref incrementInfo.startPosUnitsPerIncrement);
}

How do I pass these vector3 structs as a reference which are backed by a property field with a private setter? It seems that perhaps it's the 'in' keyword I need, but examples show that the 'in' syntax is also attached when sending in the parameters yet that gives me similar errors to using ref.

gaunt ice
#

should be impossible, properties are method and you cant ref on some return register

timber tide
#

So what's the alternative here? Just don't stick your structs inside of properties?

#

it's really a minor thing in this scenario, but I do have some larger structs of variables so it would be silly to copy them repeatedly just to read them.

#

ah, even pointers have a similar problem here too eh

gaunt ice
#

return ref? forgot if unity c# allows you to do this

north kiln
#

The property would have to be a ref return

timber tide
#

oh, I see

#

but these values are meant to be readonly as well

ivory bobcat
#

If it's just for reading, you could use the in keyword relative to methods. With properties, it's more like accessing the actual backfield although the underlying behavior would be getter and setter methods.

north kiln
#

What do you mean by readonly here, why do you care about by reference in this case if they're readonly?

remote lynx
#

guys is there a built in method for squared distance?

north kiln
timber tide
#

being ref is not actually ideal either I guess if they were modifiable, but it's a private setter property field

#

it would be in keyword I think

#

or ref readonly?

north kiln
#

I'm kinda confused, is the idea that you can't change the declaration of the SetIncrementRange method

#

and there's a compiler error because you're trying to pass a non-ref property by ref

timber tide
#

it's non-ref property

#

ill probably read into it more but that's probably it

north kiln
#

To be clear, if you use in with a non-ref returning struct property you incur a copy, and the copy is passed by ref

cosmic grove
#

guys what the hell is this?

ivory bobcat
ivory bobcat
cosmic grove
#

okay

timber tide
#

yeah it's not a big deal here, but first time I've ran into this issue which I'm surprised I've not before

topaz pendant
# cosmic grove guys what the hell is this?

Hello, have you looked at this post ? https://stackoverflow.com/questions/59829252/unity-error-does-not-contain-a-definition-for-isgameobjectinmainscenes it seems you may have to rebuild the library folder because some files may be corrupted

remote lynx
#

why do we use CompareTag and not tag==other?

north kiln
#

!ban 1196088124799979551 bot spam

eternal falconBOT
#

dynoSuccess nicholas05355 was banned.

keen dew
remote lynx
#

do i get an error or it returns null?

keen dew
#

It's a compile-time error. It always returns a boolean.

remote lynx
#

oh ok ty

languid spire
#

not a compile time error, it will throw an exception at runtime

#

== tag will not throw an exception, it will return false for a bad tag

fallow knot
#

Hi, why is the player twitching? I added delta time)

#

through the getkey component?

keen dew
#

Don't add deltaTime

dim halo
#

hey guys, so Im basically watching an old tutorial video, the guy uses 2020.3,8f1, and I have the 2021 .3.14.f1 editor would that create a problem?

dim halo
#

thank you for being helpful

fallow knot
north kiln
dim halo
fallow knot
dim halo
#

can I ask why you're using 2017?

#

just out of curiosity

fallow knot
north kiln
ionic pike
#

im doing an inventory and i wanna get some info from the Slot UI's with another script,im trying raycast and i get nothing i dont know how to do this

timber tide
#

That raycast won't work

#

if this is UI

#

to give you an idea why. Go into your scene and see where you UI is positioned compared to where your camera is at

ionic pike
#

but i have no idea how to fix it

timber tide
ionic pike
#

IPointerClickHandler does not need to be on the ui thats gonna be clicked?

timber tide
#

You stick them on components and the'll trigger

#

when you're over that specific gameobject

#

There's quite a few like IDragHandler (one of the more useful ones)

ionic pike
#

im gonna look into it thx :)

#

got it working

timber tide
#

noice

#

this will hit stuff other than the UI too I believe, but you can always iterate through for UI specific elements

shrewd swift
#

hey
can you set multiple vars with one = in chsarp ?

e.i. :

int somevar1;
int somevar2;
somevar1, somevar2 = 10;
timber tide
#

why would you var primitives

shrewd swift
timber tide
#

var is for when you don't want to type out the whole dictionary kvp

#

but seriously, the vs debugger has trouble with var

shrewd swift
rich egret
#

hi i need help

#

someone know how to solve it?

north kiln
#

Is there a code question in "it"?

timber tide
shrewd swift
rich egret
open apex
#

Hello

#

So I am trying to get the camera working

#

I can get the main camera to work like fps

#

I am now trying 2rd person but this code is giving me an error

#

could anyone explain to me why this code cannot be accepted please?

#

It's ok even if you have a theory to why it's not working

#

we can work it out together

frosty hound
#

Mouse over the error and it will tell you

#

But, you need to assign a Vector3

lunar grove
#
using UnityEngine;

public class AudioScript : MonoBehaviour
{
    private AudioSource audioSource;
    public AudioClip[] audioList;

    private void Start()
    {
        audioSource = GetComponent<AudioSource>();
    }
    public void DinoSFX(int sfx)
    {
        audioSource.PlayOneShot(audioList[sfx - 1], 1f);
    }
}

I get an argument null exception but I have already assigned the mp3s into my GameObject

#

that has this script

swift crag
#

and on what line is the error coming from?

#

please be specific when you're asking for help with exceptions

lunar grove
#
audioSource.PlayOneShot(audioList[sfx - 1], 1f);
#

this code

#

idk why

swift crag
#

well, you'd better start debugging

#

notably, what if audioSource is null?

#

although "argument null" makes me think this is an exception complaining you asked the audio source to play a null clip

#

show us the error in the console.

#

remember that we cannot see your screen..

lunar grove
swift crag
#

Okay, so that definitely means that audioList[sfx - 1] is null.

swift crag
#

you aren't putting anything into a game object

#

My guess is that you have several AudioScript components, and that one of them has missing clips

#

If you click on the exception while the game is running, the editor might select the offending object

#

(I'm not sure if it will here)

lunar grove
#

It's my playerobejct

#

but that's impossible I already audioclips into element 0 and element 1

#

i already assigned*

swift crag
#

Show the inspector for the AudioScript.

lunar grove
swift crag
#

Okay, now search your scene for other AudioScript components

#

you can do this in the hierarchy

#

t:audioscript

lunar grove
#

only my player object

swift crag
#

okay, so now we want to do some "sanity checks"

#

before you try to play the audio clip, log the clip and the current object

lunar grove
#

log?

swift crag
#
Debug.Log("I'm trying to play this: " + audioList[sfx - 1], this);
lunar grove
#

okay

swift crag
#

I wonder if you're creating a new instance of AudioScript at runtime. This will show if that's the case

open apex
#

I have fixed with a tutorial regarding vector3

#

but isn't it the same thing?

#

why wouldn't my code work?

swift crag
#

no, (1, 2, 3) has nothing to do with Vector3

#

We'd call that thing a tuple

lunar grove
swift crag
#

Looks like the error isn't happening there.

faint agate
#

I need help with something I ran into. Lets say Gun1 has 10 bullets and Gun2 has none. When I switch to Gun2, I can shoot only one bullet as if it registers the weapon switched when I click. Ill send the scripts

lunar grove
faint agate
faint agate
swift crag
faint agate
faint agate
swift crag
#

they're sometimes useful when you just want to return A and B from a function

#

(you often just use out parameters for that in C#, though)

lunar grove
swift crag
#

there is currently no exception in the console

#

are you seeing an exception in the console?

lunar grove
#

yes when the audio source plays it

swift crag
#

Then show me that.

#

I need to see what you're seeing here.

lunar grove
icy junco
#

i dont know if anyone can help me but i am making shooting game and have made it possible to shoot and setup a crossair in the middle of my screen but the bullets dont go to middle of my scrteen they are like of with 1 cm is there anyone who has had simmilar problem and could help me

    {
        Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
        RaycastHit hit;

        Vector3 targetPoint;
        if(Physics.Raycast(ray, out hit))
        {
            //hitting something
            targetPoint = hit.point;
        }
        else
        {
            //shooting in air
            targetPoint = ray.GetPoint(100);
        }

        Vector3 direction = targetPoint - bulletSpawn.position;

        float x = UnityEngine.Random.Range(-spreadIntensetiy, spreadIntensetiy);
        float y = UnityEngine.Random.Range(-spreadIntensetiy, spreadIntensetiy);

        //returning direction and spread
        return direction + new Vector3(x, y, 0);
    }```
this the code that calculates the direction
swift crag
#

source is the audio source, innit

polar acorn
swift crag
#

I don't understand why you'd get an ArgumentNullException out of this, though.

lunar grove
polar acorn
#

You're literally adding random spread

swift crag
#

Maybe if it was an extension method

swift crag
lunar grove
#

how?

icy junco
swift crag
#

and ooh, I think I get it now!

#

here's why it's happening

#

when you do GetComponent<AudioSource>() and it fails, it returns an invalid unity object

#

it doesn't literally return null, though

#

When you call PlayOneShot, it winds up doing this

#

PlayOneShotHelper(this, clip, volumeScale);

#

where PlayOneShotHelper is

#

private static void PlayOneShotHelper([NotNull] AudioSource source, [NotNull] AudioClip clip, float volumeScale)

#

notice how the first argument is called source

#

and finally...

lunar grove
swift crag
#
        IntPtr intPtr = MarshalledUnityObject.MarshalNotNull(source);
        if (intPtr == (IntPtr)0)
        {
            ThrowHelper.ThrowArgumentNullException(source, "source");
        }

oh god that's frightening

polar acorn
swift crag
#

god, I don't enjoy how Unity conflates C# null with Unity's own notion of "null"

swift crag
#

Add one.

lunar grove
#

oh do I actually have to add an audio source?

polar acorn
swift crag
#

well, yeah

#

you need one so GetComponent can find one..

lunar grove
#

like my dinoplayer gameobject?

swift crag
#

it sounds like you don't understand what GetComponent does

swift crag
#

that was really unintuitive

#

"is this null?"
"well yes, but actually no"

swift crag
#

If you call gameObject.GetComponent<Foo>(), it tries to find a Foo on gameObject

#

you can also call GetComponent on any Component type; it searches the component's game object

swift crag
#

this being "null" is so bogus

#

I expected audioSource.PlayOneShot() to immediately cause a NullReferenceException

#

(and it would have, if audioSource = GetComponent<AudioSource>() was never called)

#

it went from real null to a non-null object that Unity still considers to be null

north kiln
#

Extension methods have this behaviour regardless of Unity null

swift crag
#

Yeah, that was my first thought

#

and what Unity did wound up being kind of similar to an extension method

#

(passing this as the first argument to another static function)

faint agate
#

Can I messege or call someone to help me with someone in my game

lunar grove
#

thanks

swift crag
#

The tricky part here was how the error appeared.

lunar grove
#

It didn't help me debug it in any way lol

#

hence why I was stuck

polar acorn
faint agate
#

Lets say Gun1 has 10 bullets and Gun2 has none. When I switch to Gun2, I can shoot only one bullet as if it registers the weapon switched when I click. Ill send the scripts

faint agate
faint agate
vast vessel
#

hey lads. i set up this settings menu with a volume and music slider, but it dosnt seem to be working correctly. the volume slider is setting the master volume, but the music slider is setting both the master, and music volume. what am i doing wrong? sliders and audio mixer groups have been set up correctly

#

wait ill send the code in a sec

swift crag
#

i'm guessing that's doing it

#

oh, you fixed it in the inspector

#

musicSlider.onValueChanged.AddListener(setVolume);

#

this sounds wrong, though

#

you're calling setVolume when the music slider changes

vast vessel
#

yea

#

this code is from a long time ago, when i followed a brackeys tutorial

#

i just wanted to reuse old code and not write new code

swift crag
#

well, you probably want to call setMusicVolume when the slider changes...

vast vessel
#

already done that

swift crag
#

Your code still calls setVolume

#

read your code!

#

that explains why both sliders are changing

vast vessel
#

oooooh

vast vessel
#

since a listener has already been added for the sliders in my code

swift crag
#

Either way works.

lusty girder
#

I have a script that is trying to set the vertices of one gameobject (a standard 3D plane) to another gameobject (also a standard 3D plane).
I'm getting an error that there is no Mesh attached to Plane gameobject. I don't see how a standard Plane doesn't have a Mesh... How can I make this work?

`public class meshgrab : MonoBehaviour
{
public GameObject grab;

// Start is called before the first frame update
void Start()
{
    this.GetComponent<Mesh>().vertices = grab.GetComponent<Mesh>().vertices;
}

}`

swift crag
#

some clarifications, first

#

gameobjects don't "have" vertices

#

a GameObject is just a thing in the world that can hold components

#

a Mesh is not a kind of component. I'm a little surprised that didn't cause a runtime error.

#

You want to grab the object's MeshFilter component

#

You could just reference it directly instead of referencing a GameObject

#

so,

[SerializeField] MeshFilter source;
[SerializeField] MeshFilter destination;

void Start() {
  destination.mesh.vertices = source.mesh.vertices;
}
#

I'm not sure if you'll need to do anything else after setting the vertices property

lusty girder
swift crag
#

Mesh is a unity object class that represents mesh data

#

It won't be directly attached to a game object 'cause it's not a component

crisp moon
#

i have some questions if you all dont mind...

is 2d or 3d easier for a beginner?

what are some beginner projects because my ideas are way to complex and hard to make. like how do i com eup with an idea or know what to make?

that is all for now.

lunar grove
#
 private void Update()
    {
        GameSpeed += gameSpeedIncrement * Time.deltaTime;
        gameScore += GameSpeed * Time.deltaTime;        
        MilestoneScore();
    }

    private void MilestoneScore()
    {        
        if(Mathf.FloorToInt(gameScore) == milestoneGameScore)
        {
            audioSource.PlayOneShot(milestoneClip, 0.2f);
            StartCoroutine("MilestoneText");
        }   
    }

Anyone know why my audiosource is playing multiple audioclips even if the condition is only hit once?

#

the actual audio file sounds fine

#

when played by the game, it stacks thus making hurtful to ear to listen to

swift crag
#

if the game score increases slowly enough, it'll produce the same value when floored to an int for several frames

#

10.01 -> 10
10.32 -> 10
10.64 -> 10
10.89 -> 10

lunar grove
#

ah

#

so I just convert it into int?

swift crag
#

record the last milestone score you achieved and only play a sound if your score differs from that

lunar grove
#

comlpletely then?

swift crag
#

many score values will produce the same integer

swift crag
#

when you reach a milestone, store that score into a variable

#

only play a sound if that variable is different from the current score

swift crag
crisp moon
swift crag
#

You should start with something like !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

crisp moon
languid spire
crisp moon
languid spire
#

they are, indeed, hard to make without experience, so start simple

crisp moon
#

also sorry for my spelling im kinda dyslexic.

timber tide
#

3D is easier just because sprites are hard

true narwhal
#

i got error
u are can help me for fix this: Could not resolve all files for configuration ':unityLibrary:GoogleMobileAdsPlugin.androidlib:detachedConfiguration2'. See the Console for details.

crisp moon
true narwhal
swift crag
timber tide
#

3D animation is easier than 2D since you just lerp values

#

while 2D sprites you're drawing every frame

crisp moon
timber tide
#

of course there is resources to cheat 2D animation, but there's more popular methods of making 3D assets look 2D to get the benefit of animating them in 3D

crisp moon
#

im starting to think maybe i should make an fps or is that too hard? as i said i dream big.

languid spire
lone sable
#

Without just firing me off the ide command...

Anyone else having issues with VSCode not showing default Unity information? EG: It doesn't show me void OnEanble auto completes etc?

It used to work perfetly fine, but, I assume something got updated somewhere and now something is broken.

timber tide
#

fps is actually a little more intermediate because you're dealing more with rotations. A lot of games you can get away with just rotating on a single axis or even disabling rotation completely and moving using world coordinates with velocity.

ivory bobcat
crisp moon
crisp moon
languid spire
#

yep, not a bad idea

crisp moon
#

i would like to say thank you all for helping.

ivory bobcat
languid spire
#

I always suggest implementing existing board games because you don't need to focus on the game play, just the implementation and visuals

lunar grove
swift crag
#
int lastMilestone;

public void TryMilestone(int score) {
  if (lastMilestone != score) {
    lastMilestone = score;
    PlaySound();
  }
}
#

like so

faint agate
#

was anyone able to look at my scripts

lunar grove
swift crag
#

you could also just calculate a new milestone score whenever you reach a milestone

sullen zealot
#

hello! if i setactive to false one object then seti it true acaig, will it restart?(like the scripts, will they execute the start function again?)

swift crag
#

Start runs once.

#

OnEnable runs many times, though

sullen zealot
#

ok thanks

lunar grove
swift crag
#

in that case you don't have to check for duplicates at all

lunar grove
#

I mean only at certain points it would recalculate like at 1000 pts it would change the milstone from 100 to 250

#

something like that

sullen zealot
# swift crag No.

and can i call script functions from other scripts while the gameobject is not active?

#

it doesnt

cosmic quail
sullen zealot
#

it didnt work for me. i found another way

eternal needle
sullen zealot
polar acorn
sullen zealot
#

this is the settings script

polar acorn
#

Get the reference first

sullen zealot
#

oh

#

thanks

polar acorn
#

In general you should probably just avoid any and all functions with the word "Find" in their name

sullen zealot
#

does it affect performance?

#

bc i use it a lot in most of my scripts

timber tide
#

if you're doing it in update, yes

#

or doing multiple find operations in a single update

rare basin
#

in general you should never use any Find() method, there might be some special uses in Awake() or Start() only for singletons etc

sullen zealot
#

no im only using it in start or other events

rare basin
#

imagine you change your object name in hirearchy

#

and your scripts doesnt work

#

Find() type methods are terrible - dont use them

sullen zealot
#

is getcomponent also bad to use often?

wraith mango
ivory bobcat
sullen zealot
#

and what could i use instead of this?

sullen zealot
ivory bobcat
rich adder
wraith mango
#

alr

wraith mango
rich adder
wraith mango
#

there is a white space in between "objectives" and the actual objective, which would be fine but when I try to register that objective as completed, it thinks that the objective is in that white space

#

if that makes sense

spring skiff
#

Is there a better solution as this script?

using UnityEngine;

public class SoulFragement_Anzeige : MonoBehaviour
{
    [HideInInspector] public int SoulShards_collected = 0;
}

I mean its really everything needed.
I have 30 scripts that needs to interact with this integer.

spring skiff
rich adder
#

could look into props

swift crag
#

So you need several components to be able to share a value.

rich adder
#

use a SO

swift crag
#

using scriptable objects for sharing mutable data is fun, but can also very confusing for the inexperienced

rich adder
#

true

swift crag
#

I think what you're doing is reasonable.

spring skiff
# swift crag So you need several components to be able to share a value.

yes.
and making a script for just 1 line of code seems a bit out of place of everything other script does the work and this script is only there to contain a simple integer where every other script can have access to it, no matter if some other scripts get destroyed together with the gameobject.

rich adder
swift crag
#

There might be a better place to store the value, of course, like on a "player" component

#

if only players can have soul shards

spring skiff
#

if a gameobject gets collected by the player, it access the script, make "SoulFragement_AnzeigeSCRIPT.SoulShards_collected++; and destroys itself.

swift crag
rich adder
#

description might have the extra whitespace?

wraith mango
#

ooh that's true one sec

#

it doesn't appear to have one

#

oh wait

#

wrong screenshot

#

but still

cosmic quail
wraith mango
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "New NPC", menuName = "NPC")]
public class NPC : ScriptableObject
{
    public new string name;
    public string[] messages; 
    public string[] objectives; 
}
rich adder
#

custom class

cosmic quail
#

its just a string[] though. or is that what it looks like in the newest unity version? i havent tried

queen adder
rich adder
rich adder
eternal falconBOT
wraith mango
queen adder
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
    [SerializeField] private float moveSpeed = 7f;
    [SerializeField] private GameInput gameInput;
    private void Update()
    {
        Vector2 inputVector = gameInput.GetMovementVectorNormalized(); 
        Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
        float moveDistance = moveSpeed * Time.deltaTime;
        float playerRadius = 0.7f;
        float playerHeight = 2f;
        bool canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDir, moveDistance);
        if (!canMove)
        {
            // cannot move towards movDir

            //attempt only X movement
            Vector3 moveDirX = new Vector3(moveDir.x, 0f, 0f);
            canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirX, moveDistance);
            if (canMove)
            {
                // can move only on the X
                moveDir = moveDirX;
            }
            else 
            {
                // cannot move only on the X

                // atempt only Z movement 
                Vector3 moveDirZ = new Vector3(0f,0f, moveDir.z);
                canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirZ, moveDistance);
                if (canMove)
                {
                    // can move only on the z
                    moveDir = moveDirZ;
                }
                 else
                {
                }
            }
        }
        if (canMove)
        {
            transform.position += moveDir * moveDistance;
        }
        Debug.Log(moveDir);   
        float rotateSpeed = 10f;
        transform.forward = Vector3.Slerp(transform.forward, moveDir, rotateSpeed * Time.deltaTime);
    }

#

hello guys, so I am following Code monkeys complete tutorial for beginners and although it's fun I have a problem with this code, i have been trying to fix for a bit now (1 hours ish and its driving me crazy)

rich adder
#

use the proper sites

queen adder
#

I mean

#

tehre is a few extra }

#

and lines they are just irrelevant

#

to problem

#

and discord has caracter limitqs

#

so couldn't past whole code

rich adder
#

print them all

queen adder
rich adder
#

its annoying to read on mobile and line numbers/formatting

queen adder
#

okey I am sorry

wraith mango
#

use hastebin

#

or pastebin

rich adder
#

use the sites linked..

queen adder
rich adder
#

also share the tutorial because you probably copied it wrong

queen adder
#

💬 This was a ton of work to make so I really hope it helps you in your game dev journey! Hit the Like button!
🌍 Course Website with Downloadable Assets, FAQ, Related Videos https://cmonkey.co/freecourse
❤ Follow-up FREE Complete Multiplayer Course https://www.youtube.com/watch?v=7glCsF9fv3s
🎮 Play the game on Steam! https://cmonkey.co/kitchencha...

▶ Play video
#

timestamp : 2:14:00

#

I tried with and without f in the Vector3 though as expected it didnt change anything, I thought maybe the problem was that when I put moveDirX or Z the normal value of the vector is no longer 1 but it should have made an error for him too / didnt work when i tried to fix it in the transform forward

wraith mango
rich adder
#

also are you sure the pivots are correct

queen adder
#

(video is loading)

queen adder
queen adder
#

" transform.forward = Vector3.Slerp(transform.forward, moveDir, rotateSpeed * Time.deltaTime); "

#

I think problem is in this line

#

just don't know how to fix it

rich adder
#

yeah code monkey writes kinda bad code

queen adder
#

well he for sure claims a lot that his code is good practice and game publishing worthy lmao 🤣

#

he said it like 10 times in the first 2 hours

rich adder
#

yeah and im the president

queen adder
#

🤣

#

what country

rich adder
#

world

queen adder
#

nice

rich adder
#

anyway can you show the pivots

#

in Local Pivot mode

queen adder
#

excuse my ignorance

#

where do i find that

rich adder
#

its in the upper left corner

#

I dont have unity open rn

swift crag
rich adder
#

hopefully its not in center mode and got all offset

queen adder
#

and yeah it's in Pivot Local like shown here

queen adder
rich adder
queen adder
#

Yes, video loading

rich adder
#

oh ok screenshot would be fine

queen adder
#

ok i stopped the video ( i have bad internet)

#

but basically with this I did a test and it still doesnt the same thing

faint agate
#

can someone help me with a problem I ran into. Lets say Gun1 has 10 bullets and Gun2 has none. When I switch to Gun2, I can shoot only one bullet as if it registers the weapon switched when I click. Ill send the scripts

rich adder
faint agate
faint agate
rich adder
#

not PlayerVisual

faint agate
faint agate
queen adder
faint agate
faint agate
rich adder
#

wouldnt it have made more sense making 1 message with all the scripts instead of this scattered thing

rich adder
#

show

queen adder
#

Pivot Local

rich adder
#

do you see the problem..

#

obv not

#

lol

#

you're rotating that spot

queen adder
#

XD

#

AHAHAHAHAHA

#

ok

#

i see

#

sorry

rich adder
#

look how far the mesh is from the main object pivot

queen adder
#

I moved the playervisual earlier

#

to try smth

rich adder
#

all you need to do is reset

queen adder
#

sorry lol

rich adder
#

the position of the PlayerVisual

queen adder
#

after he does smth I pause the video and mess arround to understand more

#

and i forgot to put the visual back

#

my bad

#

good evening lads

rich adder
#

its fine, is it fixed?

queen adder
#

sorry for wasting your time

#

yes it is

rich adder
#

all good

#

see these "courses" dont teach these importance caveats of the editor

faint agate
#

would you be able to take a look at the messeges I sent

queen adder
#

but if you have any recommendations I would love to have them !

#

and i will do them as soon as finished with this one

rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

queen adder
rich adder
faint agate
#

Lets say Gun1 has 10 bullets and Gun2 has none. When I switch to Gun2, I can shoot only one bullet as if it registers the weapon switched when I click. Ill send the scripts

ivory bobcat
lunar grove
#

Can someone enlighten me with how the t argument from the color lerp works? I want to have a fixed transition time between two colors in my game

rich adder
ivory bobcat
swift crag
#

Mathf.PingPong returns a value that "ping pongs" between 0 and the second argument

#

based on the first argument

#

so 0 -> 1 -> 0 -> 1 -> ... here

faint agate
ivory bobcat
languid spire
# faint agate https://gdl.space/udosukiled.cs thats the weapon switch script

move your subscribe
PlayerShoot.shootInput += Shoot;
PlayerShoot.reloadInput += StartReload;
to OnEnable
and unsubscribe in OnDisable
also here
foreach (Transform weapon in transform) {
if ( i == selectedWeapon )
weapon.gameObject.SetActive( true );
else
weapon.gameObject.SetActive( false );

        i++;
    }

add Enable disable of Gun script

ivory bobcat
#

Implies that the default duration should be 1f

lunar grove
#

Ok, I'm starting to understand, but I need more studying it appears, having trouble comprehending

languid spire
#

think of t as %age complete where 0 is 0% and 1 is 100%

lunar grove
#

so saying that value traveling from 0 to 1 is the time it takes for it to switch colors?

languid spire
#

yes

swift crag
#

it's how far you've transitioned from the start value to the end value

ivory bobcat
#

Where the first and second are constant but t accumulate towards 1 (100%)

lunar grove
#

So lerp has to be in an update function for it to work smoothly?

languid spire
#

or a coroutine

ivory bobcat
#

For example, using age years += ... age = lerp (child, elderly, years)

swift crag
#

If you smoothly change the value of t and repeatedly call Lerp, the resulting values will smoothly change over time as well

#

do it in Update, do it in a coroutine, do it in a method that something else calls from their Update, do it in FixedUpdate...

#
void Start() {
  foo = Mathf.Lerp(0, 1, bar);
}

This will set foo exactly once when Start runs.

#

it's no different, conceptually, from just doing

#
void Start() {
  foo = 0.5f;
}
faint agate
languid spire
#

weapon.GetComponent<Gun>().enabled = false;

ivory bobcat
#

The conditions are true so the object to shoot for the gun will still occur. As to why it's not Gun1, I'm not sure because we weren't shown when you logged Gun1

#

Only Gun2 should ever log according to your code

languid spire
#

no, because all guns are always subscribed to the events set up in Start

#

private void Start()
{
PlayerShoot.shootInput += Shoot;
PlayerShoot.reloadInput += StartReload;
}

faint agate
languid spire
#

well repost your latest code

faint agate
#

foreach (Transform weapon in transform) {
if ( i == selectedWeapon )
weapon.gameObject.SetActive( true );
weapon.GetComponent<Gun>().enabled = true;
else
weapon.gameObject.SetActive( false );
weapon.GetComponent<Gun>().enabled = false;
Debug.Log("switched");

with this I get an error with the " weapon.GetComponent<Gun>().enabled = true; "

languid spire
#

so the Gun script is not on the weapon gameobject?

faint agate
#

it is

languid spire
#

also you will need to add braces

faint agate
# languid spire also you will need to add braces

I added them and now I don't get an error. When I switch from Gun1 to Gun2 it prints " Gun2 " and if I switch back it prints " Gun1 " . If I switch from Gun1, the script(Gun) attached to Gun1 disables, but I can still shoot only once

languid spire
#

so show your latest Gun script

cosmic grove
#

guys a simple question. is a ray every frame bad? like 5-6 rays per frame would cause noticable lag?

rich adder
#

you mean Raycast ?

languid spire
#

Now read what I initially wrote

cosmic grove
cosmic grove
swift crag
#

i'd be doomed if 5 raycasts per frame made your game lag

rich adder
#

there goes my enemy ML agent car 😦

#

i think it has like 12

cosmic grove
#

i mean this one isnt much of a upgrade either but yea.

languid spire
#

4gb, my first computer had 4k

rich adder
cosmic grove
lunar grove
#

Thanks for the help about color lerp, everyone I'll just continue tomorrow as I'm still having problems trying to apply it to my game

faint agate
rich adder
languid spire
lunar grove
#

then I would transition the same colors again vice versa from another if condition

rich adder
lunar grove
candid drift
#

im super new and i just closed my hierarchy where did it go 😭

rich adder
candid drift
#

where do i go to ask this question

faint agate
rich adder
#

also just reset the layout if you're confused

lunar grove
languid spire
faint agate
#

ahhh I got

languid spire
#

i.e the opposite of += is...?

faint agate
#

it workeddddd

#

thank you so much steve!

lunar grove
rich adder
lunar grove
rich adder
spring skiff
#

Now I have a fully working raycast and I think I should had better used a trigger with a 1.5meter long invisible collider in the middle of the camera...

Because I have some hiding spots that uses triggers and colliders and it seems that the invisible triggers and colliders does block the raycast and I cant collect items in a wardrobe.

frosty hound
#

You can layer mask the raycast

spring skiff
languid spire
#

you use the layermask to hit the objects which are on the layers you want or to exclude the objects on the layers you dont want. Your choice

spring skiff
languid spire
#

not tag, layer

frosty hound
#

You don't, you use layers

rich adder
thorn holly
#

So say I had this weapon in the players inventory that gains more damage when an enemy dies. The only way I can think to do this is for the enemy to create a reference to the player, and then when it dies, see if the players inventory contains that specific weapon, and if it does, change the stats of that weapon. I feel like there has to be a more efficient way to do this, but I can’t think of any.

spring skiff
rich adder
languid spire
#

do you even know what a Layer is?

silver sun
#

hi everyone i've spent 3 whole hours trying to leave the code intact while still adding a new variable that controls how intense the speed of each planet slows down when it gets closer to the planet with + 1 index than the current index and speeds up when getting further, i was hoping someone here could give me an idea and end my suffering. Here's the working code without the desired behaviour i said above:

https://pastebin.com/cnDafNgq

languid spire
silver sun
#

Cheese production please.

||Position||

languid spire
#

can't slow down cheese production, the goats don't like it

spring skiff
frosty hound
#

You create a layer mask

spring skiff
#

only confusing stuff "int layerMask = 1 << 8;"

rich adder
languid spire
rich adder
spring skiff
#

int 1 is smaller, is smaller than 8. why 8? IDK....

rich adder
#

nah those are bitshifting

cosmic quail
languid spire
#

modern day child devs, not a clue what a bit is

polar acorn
rich adder
#

give them a slack

polar acorn
#

It's a bit unfair to give that response about bitmasks in beginner code

rich adder
#

agree, they are confusing already as is let alone in beginner gamedev

thorn holly
#

Is there a way to like broadcast a signal and then any classes with specific code to take that signal can then say, execute a method?

polar acorn
silver sun
#

hi everyone i've spent 3 whole hours trying to leave the code intact while still adding a new variable that controls how intense the speed of each planet slows down when it gets closer to the planet with + 1 index than the current index and speeds up when getting further, i was hoping someone here could give me an idea and end my suffering. Here's the working code without the desired behaviour i said above:

https://pastebin.com/cnDafNgq

thorn holly
polar acorn
thorn holly
#

Awesome, thanks

lone finch
#

how to only change rigidbody2d velocity y vector

lunar grove
languid spire
#

they dont

lunar grove
balmy yacht
#

Hey, not really a coding question but i'm using the Super Character controller, but it's not working as expected, the character moves but only forwards and back, and moving left or right moves the camera, In the scene if i move the character around the camera seems to be attached to the player but in game it is not. I would like the camera to follow the character and mouse movement points where the character should be walking

languid spire
jolly jewel
balmy yacht
lunar grove
balmy yacht
#

it seems that the "actual" player is not aligned with the model

#

and the camera seems to be acting like first person???

#

it has a function to tick either first or 3rd person... strange

#

it's betetr once i align it with the model but the camera still doesn't follow the character

thorn holly
#

@polar acorn so I think I understand delegates, I just had a question. Should I have a script that only holds delegates, like a sort of delegate hub script to make adding methods to the delegates easier?

polar acorn
#

Since it's the thing that needs it, it's nice to see them all in one place

#

but there's no real performance or anything ther

languid spire
thorn holly
#

Ah i see, so I should declare it on whichever script activates the delegate?

queen adder
#

hey guys, is there a way to integrate Dali Ai into unity? Want it for a game as an image generator

#

experimenting with generative ai in 2d games

rich adder
#

if it has an API then why not..

#

most stores ban AI like that though so you cannot earn on steam at least

queen adder
#

oof

ivory bobcat
spring skiff
languid spire
#

@silver sun Actually forget what I said
Your best bet is to scrap your planetSpeeds array and implement a Planet class containing the following
Transform
Speed
DistFromPrev
DistToNext

and then you can implement simple methods to maintain these values

silver sun
#

👍

#

Transform for what purpose?

languid spire
#

so that you can pass the transform of the prev and next planets into a method and use the transform to calculate the distance between them

lone finch
#

why can i not use transform.position like this?

timber tide
#

what's the error

languid spire
#

because it's a property

lone finch
ivory bobcat
rich adder
#

properties are just fancy methods 🙂

timber tide
#

should be capitalized though

ivory bobcat
lone finch
#

so i need to declare a new variable and change position by the variable?

languid spire
#

yes

rich adder
#

it explains the fix too

languid spire
#

and then set it back

lone finch
ivory bobcat
edgy fox
#

how do I send a whole unity project for someone to test with - I have a really weird bug that someone couldnt fix even after I followed all of their suggestions and they suggested I send it to someone who can test it and find what could possibly cause said bug

languid spire
edgy fox
rich egret
#

someone know why the font like this?

rare basin
#

this is a code related channel

robust kelp
#

how can i limit rigidbody.velocity without clamping it and can i limit only vector3 x and z values

#

plz help

rocky canyon
#

you can adjust teh x and z values seperately..

#

combine them all together and then pass a new vector

swift crag
#

remove the Y component, do your clamping, and then put the Y component back in

rocky canyon
#

or that ^

swift crag
#
horizontal = Vector3.ProjectOnPlane(vel, Vector3.up);
vertical = Vector3.Project(vel, Vector3.up);

// do something to horizontal

vel = horizontal + vertical;
rocky canyon
#

not sure how one can limit it w/o clamping it tho

swift crag
#

this would work with any axis, not just the Y axis

rocky canyon
#

even if u wrote ur own if()else() conditional to stop it from going over or under, thats still a clamp

swift crag
#

useful if you want gravity to change directions (and just more pleasing to look at, IMO)

robust kelp
swift crag
#

i need to try making a game with tons of gravity shifitng

short hazel
# rich egret someone know why the font like this?

Normal. As its name suggests, Text Mesh Pro uses meshes to display your text. And to display a mesh you need a material, and to render a material you need a shader. They are the two things that appear when you expand the font asset. The converter creates a SDF (signed distance field) shader, and a material for your font.

swift crag
#

The material preview looks really funky because it's not exactly meant to be drawn on a sphere

swift crag
#

Also, if you're curious, those two things are sub-assets

#

similar to what you see on an imported model

short hazel
#

Solve?

#

There's no apparent problem here

#

Or you forgot to add it in your original question!

rich egret
short hazel
#

What makes you say that?

rich egret
#

can't put it in

short hazel
#

What steps did you do to create that font asset?

rich egret
rich adder
#

screenshot it

rich egret
rich adder
#

also not really code issue 😛

short hazel
#

Your font doesn't have the same icon as the one in the TMP_Text right now. It should also be the blue "F", instead of the generic scriptable object icon.
When creating the font asset, did the utility display any errors?

rich adder
#

Your console window i def hidden, open it

#

maybe error there

short hazel
#

Also what's the extension of the font you downloaded? And optionally make sure its license allows embedding it in software

sullen zealot
#

i have this code that gives 2 rawimages a render texture. is there any way to make the first one remain the same after assigning the render texture to it? bc if i move the camera right now both raw images modify

rich adder
#

store it inside a variable?

sullen zealot
#

what kind

rich adder
#

Texture ? RenderTexture ? w.e u want

#

probably better to store it as RT if you need to do RT specific stuff after without having to cast from inherited Texture class

swift crag
#

if you don't want the first image's contents to change..don't change them

sullen zealot
#

i tried this and it is still updating

swift crag
#

just reassigning variables does nothing