#šŸ’»ā”ƒcode-beginner

1 messages Ā· Page 305 of 1

silent dove
#

huh? i mean, im assuming its to detect them? if the enemies all have a script then it's similar to finding them with their tag?

rich adder
#

if they're already in the list you don't need to detect them, other way around

#

(assuming you already dragged them in the inspector to list)

silent dove
#

yeah i did

rich adder
#

ok so enemies need to know about that script containing the list

#

so they can remove themselves on death

silent dove
#

right, so in the enemy script it needs to find the other script?

rich adder
#

yeah, store it in a variable so it can be done only once in awake

silent dove
#

so on the start or so? and how do i go about storing it in a variable? im not entirely sure what's being stored exactly?

rich adder
#

same way you stored List in a variable?

#

the script has the list, you have to store the script

#

thats the type for the var

silent dove
#

so wait

#

i would put

#

it wouldnt be 'public script' ?

#

I really just dont get this stuff, I'm just not sure how to actually write this from nothing? im not sure what to really do going with this? idk

rich adder
#

how come you pick making a game ?

silent dove
#

its a project for this class

#

and the 2nd part of it is to make a continuation of it

rich adder
#

if its a class have you not learned anything at all?

silent dove
#

we've barely gone over a thing when it comes to coding in C#

rich adder
#

making a game is not something you learn overnight

#

its literally a process

silent dove
#

it's all been just messing with stuff in the engine itself, making particle systems and materials and stuff

rich adder
#

well coding is a whole different beast

silent dove
#

we have barely gone over a thing about code, and i realized at the start of this semester i really dont have what it takes to figure out this stuff

#

and so thats why im trying to add just a little bit more to this

#

i just really dont understand most of this stuff and im getting kind of overwhelmed i guess

rich adder
#

maybe start from the very basics and work your way back up instead of jumping into such complex tasks

silent dove
#

i mean, i was going to add a loop because i thought it would seem a bit better, but at this point i dont mind just making a simple win screen?
its just the actual detecting whether or not the enemies are still there that ended up becoming more of an issue

#

its just that we're already sofar into the class so this stuff is due pretty soon

#

i've been messing with it for a while now, but decided to try and get a bit of help, since i don't know anybody personally that uses unity either

rich adder
#

i don't see the point of these classes if you're not learning anything

#

fumbling and guessing your way around wont work in code, you need to be exact

rich adder
silent dove
rich adder
#

you only need to mainly get hang of referencing and using the basic types / functions

silent dove
#

i just dont really have much time for this, since i also have other classes to deal with at the same time, and i dont have that much longer before this stuff is due

rich adder
#

but yea explaining it will probably just go over your head unless you grab the basics, like how to work with a list (removing and adding entries etc..)

silent dove
#

right, so im not sure how to actually get the list to recognize when the enemies are being destroyed, and then i guess maybe if i can get that, then having an if the list has nothing in it, then it can do that?

rich adder
#

its not that much to do if you break it down into smaller steps. moving onto the next only when you understood what you did the previous one

#

List is useful because as you Kill off an enemy , you can modify lists to Shrink in this case. this gives you sort of a count down

naive pawn
#

couldn't you use a gameobject as a container for the enemies and when you Destroy them they get removed from the gameobject

rich adder
#

thats the idea..

naive pawn
#

i just got here, mb.

rich adder
#

but the current script that contains list of enemies is in another script and they're confused on why they need refrences to it

silent dove
#

i see

rich adder
rare basin
#

better to have direct references to the Enemy in the list

naive pawn
#

uh what

rich adder
#

well yeah its good practice

#

if its a Component it already has a .gameObject property and a .transform

naive pawn
#

im confused why that's aimed at me

rich adder
#

dunno lol

silent dove
#

and then i have the enemyManager right now that's empty currently

rich adder
#

correct, enemyLoop becomes enemyManager because enemyLooping makes no sense

silent dove
#

or well, enemyLoop is the name of the file, uhh

rich adder
#

keep name of file and classes the same or unity will throw a fit

silent dove
#

yeah theyre the same

#

the class is enemyloop and the file is enemyloop

#

this is what that one has

#

and then the enemyManager is empty right now

rich adder
#

yes just needs a public method that it can receive the GameObject enemy to remove

silent dove
#

so it needs a public void? how would i go about having it receive the GameObject enemy?

rich adder
#

as long as you declare it

silent dove
#

so i would make a public void and call it

#

idk

#

enemydetect? or something like that? and it would have a parameter, but how would i get the parameter? im not sure

rich adder
silent dove
#

public void enemydetect()

#

or something of that sort

rich adder
#

but inside () you declare what type of data this method can receive , in this case can either be GameObject or whatev your enemy script is (since this is what needs to remove from list)

silent dove
#

so just saying GameObject? or would it need to be the actual list itself?

vagrant fjord
#

i have implemented a recoil animation and when i am out of bullets the animation still plays. Can anyone help?

eternal needle
vagrant fjord
#

how? im very new to unity and dont really know

eternal needle
#

you'll have to share code so we know how you are even playing the animation in the first place

languid spire
vagrant fjord
#

how can i connect the two scripts

languid spire
rare basin
#

is this chat gpt code?

vagrant fjord
vagrant fjord
rare basin
#

yea i can tell

#

don't use chat gpt if you are just starting and learning

vagrant fjord
#

so any ideas?

rare basin
#

do you know basics of c# or/and unity?

#

if not i'd start with that instead of blidnly copy&pasting chatgpt generated code

#

without understanding it

vagrant fjord
#

yeah relatively

#

i tried every tut on the planet and none worked

eternal needle
#

that sounds more like a user error rather than it not working

#

right now your scripts have no relation. think about it logically, you have logic for when you are able to shoot. the animation should be done from there. Follow this to learn how to reference another script https://unity.huh.how/references
Right now your animation is completely unrelated to the shooting. Both just happen to exist at the same time

vagrant fjord
#

alr ill try that

eternal needle
#

you are already referencing another script also in RecoilScript, which i assume chatgpt wrote for you.

#

you should cache that value, because you dont need to get it every single time its done. get it once and store it

languid spire
rare basin
#

is your IDE configured? let's start with that

vagrant fjord
#

yeah it is

rocky gulch
#

weird question but let say i got two of these objects

Class Object1 : MainObject, Interface1 {}
Class Object2 : MainObject, Interface2 {}

what would happen if i did

MainObject a; //(derived from Object1)
public void ChangeObject(MainObject b){
   a = b
}
//(b is derived from Object2)
#

will the interfaces remain intact
or will everything be replaced

rare basin
#

the object reference a will be replaced with the object reference b, but the interface implementations will remain intact @rocky gulch

rocky gulch
#

alright just what i wanted

#

thanks (codes still messy i cant test(

split dragon
#

Hi. I have a question: I have a variable by component, let's say light. I want to create a local variable: "GameObject", which will be equal to the light variable, but you cannot assign a GameObject via a component variable. How do I access the object that has this component? An example of what I want:

split dragon
spiral narwhal
#
    public interface IProgress<T> where T : ScriptableObject
    {
    }

Is there a better way to force implementations to be SOs? Because with this, I don't use T, which gives warnings

teal viper
#

You could use an abstract SO as a base class though

#

Instead of an interface

spiral narwhal
#

No, sorry if I phrased it weirdly. Consider this:

    public class BountyHuntGameSubtaskProgress : IProgress<BountyHuntGameSubtask_SO>
    {
        private readonly BountyHuntGameSubtask_SO _referencedSubtask;

        public BountyHuntGameSubtaskProgress(BountyHuntGameSubtask_SO referencedSubtask)
        {
            _referencedSubtask = referencedSubtask;
            Progress = new(referencedSubtask.SpaceshipTypesToHunt);
        }

        public Dictionary<SpaceshipType, int> Progress { get; }

        public BountyHuntGameSubtask_SO GetReference() => _referencedSubtask;
    }

I use the interface as a wrapper class for tracking progress of ScriptableObjects

#

I managed to circumvent the warning by introducing the generic GetReference() method

#
    public interface IProgress<out T> where T : ScriptableObject
    {
        public T GetReference();
    }
teal viper
eternal needle
# rocky gulch will the interfaces remain intact or will everything be replaced

Just a note about this. Since you are using MainObject here as the type, you only have access to variables or methods associated with MainObject, not Object1 or 2. This would mean you wouldnt be able to use stuff from the interface, unless you cast or Object1 or 2 override a method while using the interface as it wants

tough cave
#
public class MovementController : MonoBehaviour
{
    public Rigidbody player;
    public float speed;

    
    public void Move(Vector3 movement)
    {
        player.AddForce(movement * speed);
        
    }

Is addForce not applied on the rigidbody? I'm trying to not let the player walk through walls, tried to fix that cuz i used transform. and i believe tahts the wrong function to use, so now I use Addforce. But now it wont move at all.

tough cave
#
 void Update()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        movementController.Move(movement * Time.deltaTime);
    }
rich adder
#

addforce is using mass, so also there is that

#

check ur rb settings, how much is ur speed set?

languid spire
#

also you should not be using deltaTime in that scenario

rich adder
#

yea prob holding it back too rn

tough cave
#

I tried seting it between 5 till 5000. no difference yet. I removed deltaTime, and turned the method into FixedUpdate. No movement yet :c
It stopped working after I changed the type of GameObject to Rigidbody since I wanted to use 'AddForce'. Could that be it?

rich adder
tough cave
rich adder
#

kinematic = not affected by forces

tough cave
#

Oh. now it shot me forward yea. But I fall through the ground/plane if thats unchecked.

rich adder
languid spire
#

yes, your collider is a trigger

#

did you do any research at all before using this stuff?

queen adder
#

Hello guys, I'm trying to share my project on github. But I realise that when I build my project, I can't see the source codes in the files. So basically whenever I upload it to github, people cannot see what kind of codes I wrote it for the project. Am I missing something? I'm really confused to fix that problem.

rich adder
#

the source code is inside the dlls

#

if you want to share a git project you need to make a repo from the project folder itself

queen adder
#

How can I do this?

rich adder
#

easiest way using git

#

proably a GUI

queen adder
rich adder
#

most people who can do it probably wont care about your source code lol

queen adder
#

I'm just doing this for portfolio, so I just want other people can see the scripts that I wrote for the project. It's all deal

rich adder
#

if you want the project itself , you would need to commit the project folder where the Asset folder is

#

if its a portfolio should probably learn the how to make repos

queen adder
#

Ahh all right, so I shouldn't upload the build. I should upload the main folder. Okay it's make in sense now

queen adder
modest quarry
#

NullReferenceException: Object reference not set to an instance of an object Player.FixedUpdate () (at Assets/Player.cs:30)

#

whats this error i only get it once when starting game

#

then when i start it again it goes

#

so i cannt build the game cuz ofthis error

rich adder
modest quarry
#

like the game gets build

#

but doesnt play

rich adder
#

whatever is on line 30 on Player is null

#

but you're trying to access it

modest quarry
#

oh

vagrant fjord
#

im trying to stop the recoil animation when i have no bullets and its not working

modest quarry
#

so its the input

#

wait why am i trying to convert it to float

rich adder
#

thats the only thing that can be null yes the others are value types

modest quarry
#

i thought it resuts in -1,0,1

#

cuz i was using raw before

#

thats why

rich adder
#

raw still returns a float

modest quarry
#

i removed float still same error

rich adder
#

float aint the error buddy

modest quarry
#

inputManager

rich adder
#

value types are not null

#

inputManager is null

modest quarry
#

lol

#

so its cuz i set it in Start right

rich adder
#

assign in awake

modest quarry
#

yeah done

rich adder
#

it still errors ?

modest quarry
#

nope

#

thanks

vagrant fjord
modest quarry
#

even the build works :D

rare basin
rocky gulch
#

well my intention was to just change the variables
so im assuming just list of object1 and object2 then using cast to change the values

thorn holly
#

Wait, this is chat gpt code?

cosmic dagger
thorn holly
#

Out of curiosity, why is it that some variables have to be set in Start() or a method and some can be set in a class outside of any methods?

rare basin
#

such as?

wintry quarry
#

If it's not a compile time constant you can't set it in a field initializer

slender nymph
#

it's not just compile time constants, it is anything that can be accessed within a static context

wintry quarry
#

(or a static member)

#

🐢

slender nymph
thorn holly
tender stag
#

why is it not going to the end?

rare basin
#

debug fillAmount

#

or check the UI anchors

#

also you can just ues dotween, would be simplier in your case with the OnComplete() method so you can handle the crafting

tender stag
#

its just the bar

rare basin
#

didin't say it doesnt

tender stag
wintry quarry
#

Fields are the class-scoped variables declared inside a class but outside any methods

thorn holly
#

So if I make the field public int m and set it to 10, would it look like this in a field initializer? public int m = 10

#

I’m confused cause you said I can only set compile time constants in a field initializer, but I didn’t put the const there yet it still works

slender nymph
#

the integer literal 10 is a compile time constant

thorn holly
#

Ohhhh, so I can only set it equal to a compile time constant

tender stag
#

the craft time is 10 seconds

slender nymph
tender stag
candid gate
slender nymph
#

you aren't using a layermask so it's possible that you are hitting the player with the linecast (and you only ever print when it hits something other than the object tagged as Player). also you should be using the CompareTag method rather than string equality when checking an object's tag

thorn holly
slender nymph
#

no, that would work just fine. however it is also serialized so the value assigned in the inspector would be what is used. but assigning inside of Start would overwrite that serialized value

thorn holly
#

Ah, I see, thanks

candid gate
pine umbra
#

Hi Guys, Do you use GitHub version control (or any other) for your games' data?

rare basin
#

ofc

pine umbra
#

But does it have sense to do that for small projects also?

polar acorn
#

Makes more sense than for big projects honestly. A small project might actually fit in the amount of LFS you get with the free tier

rare basin
pine umbra
#

Thank you guys. It's always very usefull to consult suff with more expirienced

silver dock
ivory bobcat
silver dock
ivory bobcat
#

(tbh, it looks like you've forgotten to set the physics matrix to avoid collision between characters)

ivory bobcat
silver dock
undone rampart
languid spire
ivory bobcat
#

We don't know anything about what they're doing.

#

Other than not wanting the characters to push each other but needing them to collide

silver dock
# ivory bobcat We don't know anything about what they're doing.

Its simple, at least i think so

  1. The players should act as walls to each other, not passing through, not pushing it away
  2. but also my "push" feature which i intentionally added should push the players away with a specific key

So basically i want the pushing to only happen when that key is pressed, and other than that it shouldnt normally push them away while just walking like how it is now

#

i tried setting the mass to very high, but both of them need to be high mass then, which then just makes it pointless, and then i couldnt jump also

lilac hemlock
#

https://gdl.space/filutibaye.cpp

Can someone help me out please. I am trying to make my ship to roll to 90 degrees when the button is pressed. The button is working, but the ship doesn't want to roll to the desired angle.

languid spire
silver dock
#

but simply im very dumb

languid spire
#

do you not know what velocity is?

silver dock
#

not really

languid spire
#

then you cannot be helped. you need to learn at least some very basic physics

silver dock
lilac hemlock
rare basin
#

if you want to make physics based operations, then you'd obviously need some basic physics knowledge

silver dock
silver dock
rare basin
#

then if you dont understand what is velocity from google

#

what are the chances you'd understand it from someone else

ivory bobcat
silver dock
rare basin
#

there is no riddle lol

polar acorn
rare basin
#

you dont need to understand all the formulas

polar acorn
languid spire
silver dock
rare basin
#

it doesn't

#

you just learned what is velocity

silver dock
#

goes

languid spire
#

goes down to what ?

silver dock
#

zero

frosty lantern
#

hey how exactly do we tell if we have beginner, general, or advanced issues?

frosty lantern
#

Yeah

lilac hemlock
languid spire
#

exactly, so when your 2 players collide, to stop them pushing set their velocity to zero

summer stump
frosty lantern
#

hey how do i get the console errors to display on multiple lines?

#

or just all console messages

#

like the log entry works for more information but long messages still overflow sideways

#

So I have to maximize the console to see the whole message

slender nymph
#

just click the log and look at the stack trace window at the bottom of the console window

#

you don't have to make your console even larger just to see that info

opaque bough
#

i have a code that says when i click the "E" button, to set the object to be a child of the camera. it works, but i have to click the "E" key about 500 times for it to do anything what am i doing wrong?

slender nymph
#

sounds like you are using GetKeyDown inside of FixedUpdate

#

of course you haven't bothered showing code so that is only a guess

opaque bough
#

lemme share the code

silver dock
opaque bough
frosty lantern
#

thanks

lofty sequoia
#

can't you use AddForce or something on rigidbodies

slender nymph
# opaque bough code

GetKeyDown is only true for a single frame when you press the key. this isn't necessarily a FixedUpdate/Physics frame. so using that in OnTriggerEnter is not going to work the way you want

languid spire
slender nymph
#

i recommend looking into using a raycast or physics query to determine whether an object can be picked up instead of relying on physics messages

opaque bough
silver dock
slender nymph
opaque bough
#

hm, so how do i make it every frame?

rare basin
#

raycasting, ontriggerstay (yet i dont recommend it tbh)

#

many possible ways

languid spire
real falcon
#

is it possible to just relight one area of the map not the entire scene?

ivory bobcat
# frosty lantern hey how exactly do we tell if we have beginner, general, or advanced issues?

There really isn't a way to measure but imo if you're simply exploring the language, api or are having difficulties understanding a certain error/unwanted-behavior like syntax errors, null reference exception errors, improper type conversion errors and whatnot.. Unity beginner code should be fine. General coding issues with Unity would be imo more about standard issues like exploring design patterns, generic constraints/limitations, how data should be managed and anything revolving more design and less "help me get started" or "what's wrong with what I've got given X". Where they both overlap would be with reading/tutorial suggestions as the level of complexity these suggestions provide can vary tremendously. As for advance, it's likely for those who want to have discussions on something they've learned elsewhere and how they could integrate/implement these very specific systems with Unity - a difficult, large or tedious task for an individual does not necessarily make it an advance topic. Expect more criticism inside general/advance and hopefully less traffic (questions and responses). Just stick with beginner code if you've got simple problems or are wanting to provide less complex solutions. General and advance code if you're wanting longer discussions. This is all voluntary so don't expect any personal tutoring.

lean finch
#

guys how can i set animator other animations?

timber rock
#

Hello, everyone! I have a question regarding ground detection.

I'm currently working on a rigid body based character controller and, so far, I checked if the player character is grounded by using the CheckSphere method but it doesn't behave exactly the way I want it to. I have been looking for solutions on the internet and most people say I should be using a raycast or spherecast. Since raycasts cannot handle situations when the character is walking over very small gaps between two platforms, I believe using a spherecast is the way to go.

My question is:
Would using the Spherecast method in order to check if the player character is grounded make for a good solution or is it too expensive?

#

Also, if you know a more clever way and are inclined to share, please do so. :)))

wraith valley
#

Help please

#

Again this

#

I did what I should have done

swift elbow
#

or something like that

wraith valley
#

But it should assign

deft grail
wraith valley
deft grail
wraith valley
deft grail
#

your using the Old Text, you should be using TextMeshPro

wraith valley
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class addScore : MonoBehaviour
{
    public TMP_Text text;
    public addScore addscore;
    // Start is called before the first frame update
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Score.score++;
      text.text = Score.score.ToString();
        
    }

    void Start()
    {
       
    }

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

    }
}
swift elbow
#

you have to do it your self

#

drag and drop them in the editor

deft grail
#

@wraith valley your using the Old Text, you should be using TextMeshPro

deft grail
wraith valley
languid spire
swift elbow
wraith valley
deft grail
swift elbow
deft grail
languid spire
# wraith valley

that is not a reference, that is a declaration. references are set in the inspector which says NONE

deft grail
wraith valley
languid spire
#

you've dragged in nothing

deft grail
languid spire
deft grail
#

the exact thing your dragging

wraith valley
summer stump
wraith valley
summer stump
languid spire
wraith valley
wraith valley
stuck palm
#

i did this and now all my textures are stuck on that after play mode, how do i fix? i just want it to scroll a texture but it appears to have scrolled every texture

void Update()
    {
        _image.material.mainTextureOffset += speed * Time.deltaTime;
    }
wraith valley
#

With prefab

ivory bobcat
ivory bobcat
#

Reminder that if you decide to prematurely destroy the object, you ought to destroy the material as well - loading a new scene will automatically do this for you though.

hazy minnow
#

can someone tell me how to acces another variable from another script

young warren
#

or google "how to access variable from another script unity"

ivory bobcat
hazy minnow
#

!code using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LogicScript : MonoBehaviour
{
public int playerScore;
public Text scoreText;
public GameObject gameOverScreen;
public float highScore;
public Text hightScoreText;
public float score;
public PipeMiddleScript piper;

[ContextMenu("Increase Score")]
public void addScore(int scoreToAdd)
{
    playerScore = playerScore + scoreToAdd;
    scoreText.text = playerScore.ToString();
}

public void restartGame()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void globalHighScore()
{
    piper.high = score; 
}
public void gameOver()
{
    
    gameOverScreen.SetActive(true);

    if (score > highScore)
    {
        highScore = score;
        PlayerPrefs.SetInt("highScore", (int)score);
        hightScoreText.text = "High Score: " + highScore.ToString();
    }
}

}
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;

public class PipeMiddleScript : MonoBehaviour
{
public LogicScript logic;
public AudioSource sound;
public float high = 0;
// Start is called before the first frame update
void Start()
{
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
}

// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
   if (collision.gameObject.layer == 3)
    {
        high = high + 1;
        logic.addScore(1);
        sound.Play();
    }

}

}
why my score var don't work

summer stump
#

Likely you are getting confused by having playerScore and score

#

Then assigning to playerScore but trying to USE score

hazy minnow
#

I want to make when you go touch the collider the score get higher

swift elbow
hazy minnow
#

ok

summer stump
hazy minnow
frosty lantern
#

hey if I instantiate an object based on a prefab, and that prefab has a script, and that script contains a variable containing a script such as a CoordinateSystem cs = new CoordinateSystem(), can I access that Coordinatesystem in the line after instantiating the object?

frosty lantern
#

because I'm getting a nullreference and wanted to make sure it wasn't just bad timing

thorn holly
swift elbow
thorn holly
wintry quarry
#

you don't need GetComponent

frosty lantern
#

PieceSetup has an error on 122

tacit kestrel
#

hello. i have a rhythm game i am working on. i am having a specific issue with a lag spike that happens when i hit the first note, and then never again. looking at the profiler it seems to do some huge reallocation at that time for some reason. what could this be?

thorn holly
#

He’s instantiating a prefab

#

And it has a component

wintry quarry
thorn holly
#

And he wants to get a variable in that component

wintry quarry
#

you don't need GetCOmponent for that at all

young warren
#

Praetor knows what they're talking about lol

rocky gale
#

hi, i am using netcode for gameobjects and i am trying to make a health system where if your health is 0 you die. i have an interface which has a damage method, and in my gun i have a raycast and when you click it invokes the method and damages the player. in the player i check if the health is equal to or less han 0 and destroy it. how would i go about making the server destroy the player because right now if the client kills the host i get the error [Netcode-Server Sender=1] [Invalid Destroy][Player(Clone)][NetworkObjectId:1] Destroy a spawned NetworkObject on a non-host client is not valid. Call Destroy or Despawn on the server/host instead.

wintry quarry
#
[SerializeField] ChessPiece prefab;

void SpawnPiece() {
  ChessPiece instance = Instantiate(prefab);
  var whatever = instance.whatever;
}``` @thorn holly
#

no GetComponent required

frosty lantern
wraith valley
summer stump
wintry quarry
#

it's just an example

wintry quarry
#

Anyway why would we want "GameObject" anywhere in here?

thorn holly
wintry quarry
#

yes

thorn holly
#

I did not know that was a feature

wintry quarry
#

it also guarantees that you can only reference an object that actually has ChessPiece on it

thorn holly
#

I learned something new today

wintry quarry
#

which would have saved this person from this problem

young warren
frosty lantern
#

I fixed it

wintry quarry
thorn holly
young warren
#

uh, sure?

dire tartan
#

how do i prevent my player from sticking to the side of a wall if a force is being added in the walls direction

pine umbra
#

Hi Guys, How do i repair/ prepare my audio file to fit in audio source? Cause when i downloaded my sound from yt it didn't work

dire tartan
#

ive added a physics material but that only works when the player isnt waling into the wall

young warren
thorn holly
swift elbow
#

a physic material should be all you need

pine umbra
frosty lantern
pine umbra
young warren
#

and where is your audio file

pine umbra
wraith valley
#

What is ```rb.velocity = new Vector2(moveInput * speed * Time.deltaTime, rb.velocity.y);

pine umbra
young warren
wraith valley
#

Why rb.velocity.y is there?

wintry quarry
#

to preserve the existing velocity on the y axis

dire tartan
wraith valley
wintry quarry
#

y axis is up and down

swift elbow
pine umbra
wraith valley
#

Why? If he only wants to move left and right?

dire tartan
#

yeah i was wondering how to avoid the issue

wintry quarry
#

and most coordinate systems

wraith valley
#

No

swift elbow
wraith valley
#

Why save y speed if he uses x speed?

young warren
wintry quarry
wintry quarry
pine umbra
frosty lantern
wintry quarry
#

it's wrong

young warren
#

maybe show a video of you dragging the file to the slot

frosty lantern
wintry quarry
#

Instantiate creates everything

#

there's nothing to attach

#

it's already attached

#

attach it to what?

#

Instantiate will:

  • Clone the entire prefab
  • Return the reference to the ChessPiece script attached to the new clone
frosty lantern
pine umbra
wintry quarry
frosty lantern
summer torrent
#

Hey, I've tried using https://docs.unity3d.com/Manual/WheelColliderTutorial.html and i fixed a few errors but now it just says foreach statement cannot operate on variables of type 'WheelControl' because 'WheelControl' does not contain a public instance or extension definition for 'GetEnumerator' and i don't really know what to do

frosty lantern
#

I still haven't fixed the : Monobehavior on the scripts

wintry quarry
#

it should be WheelControl[] but you just wrote WheelControl

summer torrent
#

ok lemme try

#

oh, it's gone

#

thanks

hazy minnow
#

how to save the highest score

rich adder
#

if(currentScore > highestScore) Save()

hazy minnow
#

ok

#

how do I use the score that was saved

rich adder
hazy minnow
#

but how do I load it at the begin of the game

rich adder
signal dew
#

Hey does anyone know how to instantly drag a game objects after spawning it?
(I have a button that spawns a game object on the mouse when you press it. I want it to spawn and then instantly drag it without letting go of the left mouse button and then despawn when you let go of the mouse button. So that pressing the button and dragging the object is one smooth motion.)

wintry quarry
hollow remnant
#

I want to make this by procedural function...

#

..but did this

signal dew
wintry quarry
hazy minnow
#

!code using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEditor;

public class LogicScript : MonoBehaviour
{
public int playerScore;
public Text scoreText;
public GameObject gameOverScreen;
public float highScore;
public Text hightScoreText;
public float score;

[ContextMenu("Increase Score")]
public void addScore(int scoreToAdd)
{
    playerScore = playerScore + scoreToAdd;
    scoreText.text = playerScore.ToString();
}
void Start()
{
    if (PlayerPrefs.HasKey("highScore"))
    {
        highScore = PlayerPrefs.GetInt("highScore");
    }
}
public void restartGame()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void gameOver()
{
    
    gameOverScreen.SetActive(true);

    if (score > highScore)
    {
        highScore = score;
        PlayerPrefs.SetInt("highScore", (int)score);
        PlayerPrefs.Save();
        hightScoreText.text = "High Score: " + highScore.ToString();
    }
}

}
Can sommone tell me how to make that the highscore is actually changed because it doesn't work

eternal falconBOT
rich adder
#

are you sure the script is running also where are you increasing score?

hazy minnow
#

yes the code is running but it overwrite the highscore function by 0

slender nymph
#

you don't actually display the high score until you save it in the gameOver method

wintry quarry
rich adder
hazy minnow
#

ok

outer cobalt
#

I have a couple of respawn points that have the same animation that if the player collides, it plays a animation, but it resets the copies of the respawn point to the same point as the first respawn, how can i fix this?

rich adder
#

esp if they share the same animation you will have problem , make sure it only moves local

summer torrent
#

unity tutorial, again (it broke my wheels)

outer cobalt
#

how would i make it local?

rich adder
signal dew
wintry quarry
rich adder
summer torrent
# rich adder not. code question, also is the model thats messed up

umm i think it's this code

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

public class WheelControl : MonoBehaviour
{
    public Transform wheelModel;

    [HideInInspector] public WheelCollider WheelCollider;

    // Create properties for the CarControl script
    // (You should enable/disable these via the 
    // Editor Inspector window)
    public bool steerable;
    public bool motorized;

    Vector3 position;
    Quaternion rotation;

    // Start is called before the first frame update
    private void Start()
    {
        WheelCollider = GetComponent<WheelCollider>();
    }

    // Update is called once per frame
    void Update()
    {
        // Get the Wheel collider's world pose values and
        // use them to set the wheel model's position and rotation
        WheelCollider.GetWorldPose(out position, out rotation);
        wheelModel.transform.position = position;
        wheelModel.transform.rotation = rotation;
    }
}
wintry quarry
summer torrent
rich adder
hazy minnow
uncut shoal
#

I made a function which generates a mesh for a 2D chunk in my game so that I can render it with Graphics.DrawMesh, how do I give each tile on the chunk its own texture

rich adder
hazy minnow
#

it change when we click on Play Again

rich adder
#

thats how you want it ?

hazy minnow
#

and it's okayy

#

yes

uncut shoal
#

Currently my entire mesh is using a single sprite, but how do I make each tile able to have its own sprite

hazy minnow
#

just asking myself what are these weird noses in the video

summer torrent
signal dew
rich adder
eternal falconBOT
rich adder
wintry quarry
#

so I don't know how you expect to move the instantiated thing if you're not even keeping a reference to it

summer stump
eternal falconBOT
summer torrent
rich adder
#

that too

summer torrent
#

i'm like rlly new to unity

rich adder
rich adder
summer torrent
#

idk how to check

rich adder
#

don't think, be sure

lethal bolt
rich adder
summer stump
lethal bolt
summer torrent
rocky canyon
#

it'll help u line up pivots and such..

summer stump
rocky canyon
#

by locking it front view, left view, top view etc

rich adder
#

use a better script

rich adder
#

or the license plate iirc was "OuttaTime"

rocky canyon
#

hehe, itch assets ftw

hazy minnow
#

I changed the script now the high score will show before death

rocky canyon
#

we can call it a stainless steel coupe

rich adder
signal dew
wintry quarry
#

the actual object that gets spawned is returned by Instantiate

#

you're ignoring that

summer stump
wintry quarry
#

And that spawned thing is the very thing you need to be moving

#

so it's hard to move that thing when you're not even storing a reference to it

rocky canyon
#

until the nueralink plugin

signal dew
wintry quarry
wintry quarry
#

As I said, Instantiate returns it

summer stump
#

I just showed you

wintry quarry
#

it exists as soon as you call Instantiate

#

and yes

#

it's been shown to you

signal dew
#

ohhh i completely overlooked that sorry :')

amber spruce
#

how do i make a gameobject that has a script attached that has values that can change and can be accesed and changed from anywhere in the current scene and other scenes

wintry quarry
#

make a script, put a variable on it

#

put the script on an object

uncut shoal
#

Can someone help? I have a function which generates a mesh for a chunk in my 2D world, but currently all of the tiles that are inside the chunk are drawn with the same sprite. How do I make it use multiple sprites?

#

The mesh is drawn using Graphics.DrawMesh

wintry quarry
uncut shoal
#

each tile in my system has a list of 'Elements' which are basically what make up the tile

#

a floor, a wall, a roof, an item.

wintry quarry
#

that sounds more like an internal data structure thing than a Rendering thing

uncut shoal
#

yes

#

but if I want to render that

wintry quarry
#

for rendering you could use a Tilemap

uncut shoal
#

I can't render it with a Tilemap

#

because a tilemap doesn't let me stack textures

wintry quarry
#

you could use multiple tilemaps - one for each layer of stacking

summer torrent
#

can i make this:
wheelModel.transform.rotation = rotation;
but with only one axis?

uncut shoal
#

Yeah but I thought it would be more performant to program something that is more suited to my data structure

summer torrent
rich adder
wintry quarry
frail star
#

How can I restrict this from adding all the contents of triviaJson.text into triviaDatabase?

JsonUtility.FromJsonOverwrite(triviaJson.text, triviaDatabase);

triviaJson.text has 547 questions , triviaDatabase is a list to hold the data , I wanna clear the list on start with list.clear() then refil the list with a specific number of questions from triviaJson.text

uncut shoal
#

for each stack

wintry quarry
# summer torrent x axis

project the forward direction of the object in question on a plane with the x axis as the normal, and use that with Quaternion.LookRotation to produce the new rotation

uncut shoal
#

if it is needed for that specific tile

wintry quarry
rich adder
uncut shoal
#

Ok fine

#

should I have a separate tile map for every single chunk or one for the entire map

wintry quarry
#

sounds like you probably want a tilemap for each chunk and each layer

frail star
uncut shoal
#

it kinda depends on whether tilemaps already do performance things like culling tiles that aren't visible right now

#

if it doesn't I'd probably have to create a tilemap stack for each chunk

polar acorn
rich adder
uncut shoal
#

Then I believe it would be better and more performant to have a single stack of tilemaps for the entire map

frail star
uncut shoal
#

so 3 tilemaps, assuming I have a floor layer, a middle layer, and a roof layer.

rich adder
frail star
south dagger
#

hey, im trying to make a leaderboard using google play services. To show the UI, im using Social.ShowLeaderboardUI();, but it doesn't work. I have to use another code or something? Thanks!

uncut shoal
#

unless I decide to allow players to create multifloored buildings

vestal shadow
south dagger
polar acorn
rich adder
#

don't listen to it

south dagger
rich adder
south dagger
vestal shadow
#

i have faced a similar issue before

#

with the play store

south dagger
vestal shadow
rich adder
rich adder
#

seems to be related to Android

south dagger
rich adder
south dagger
south dagger
rich adder
#

nothing saying thats the case though.

#

The other functions work ?

south dagger
# rich adder ohh yeah last time I used their plugins nothing would work lol I just used anoth...

yeah it makes sense, btw this video shows more or less what i did, if its helpful: https://www.youtube.com/watch?v=lCZd_URHVK8

In this video, I show you how to set up your Google Play services so that you can add leaderboards to your Unity game!

Link to Play Games package: https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/current-build

Download Mighty Mini Golf (for free!):
iOS: https://apps.apple.com/us/app/mighty-mini-golf/id1614873320
Andr...

ā–¶ Play video
rich adder
#

show your current code

south dagger
rich adder
#

did you make sure is running at all

rich adder
#

or is it just UI not working

south dagger
south dagger
# rich adder show your current code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using TMPro;

public class playGamesManager : MonoBehaviour
{
    //private const string leaderboardNormal = "CgkIm56s2cEQEAIQAQ";
    //private const string leaderboardEasy = "CgkIm56s2cEQEAIQAg";
    //private const string leaderboardHard = "CgkIm56s2cEQEAIQAw";

    public static playGamesManager playgamesmanager;
    public TextMeshProUGUI DetailsText;
    public bool connectedToGooglePlay;

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

    public void SignIn()
    {
        PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
    }
    internal void ProcessAuthentication(SignInStatus status)
    {
        if (status == SignInStatus.Success)
        {
            // Continue with Play Games Services
            connectedToGooglePlay = true;
            string name = PlayGamesPlatform.Instance.GetUserDisplayName();
            string id = PlayGamesPlatform.Instance.GetUserId();
            string ImgUrl = PlayGamesPlatform.Instance.GetUserImageUrl();


            DetailsText.text = "Success \n " + name;

        }
        else
        {
            DetailsText.text = "Sign in Failed!!";
            connectedToGooglePlay = false;
            // Disable your integration with Play Games Services or show a login button
            // to ask users to sign-in. Clicking it should call
            // PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
        }
    }

    public void LeaderboardUpdate(bool success)
    {
        if (success) Debug.Log("Updated Leaderboard");
        else Debug.Log("Unable to update Leaderboard");
    }

    public void ShowLeaderboard()
    {
        Social.ShowLeaderboardUI();
                
    }   
}
#

this is the code of the gameobject that manages the things about the google play services

rich adder
#

and is text saying "success"

south dagger
rich adder
#

how are you calling ShowLeaderboard ?

#

put log inside to see if function runs at all

south dagger
south dagger
#

yeah it works actually

#

it calls the function

rich adder
#

well since this seems to be play/android related, i'm gonna assume that function may need to run within the android enviroment

#

it probably uses native UI

#

so nothing unusual

south dagger
south dagger
#

there is like two methods to do that, the second one is the one that works for me, but it only shows one leaderboard

rich adder
#

so make the function for all of them

#

maybe because you have multiple ones it doesn't know which to open unless you specify

south dagger
rich adder
#

yea
like
PlayGamesPlatform.Instance.ShowLeaderboardUI("1");
PlayGamesPlatform.Instance.ShowLeaderboardUI("2");
PlayGamesPlatform.Instance.ShowLeaderboardUI("3");

south dagger
#

oh yeah but in the same function??

rich adder
#

yup

amber spruce
south dagger
rich adder
amber spruce
south dagger
#

but i dont really now if it works

wintry quarry
#

Your question was just extremely vague

#

like you literally provided no details at all

amber spruce
#

its to hold the variable of what is the current save slot

#

not sure if that helps

wintry quarry
#

SOunds like something a SaveGameManager or something like that should handle

#

it should live there

#

If you're asking how to get a reference to such a script, then sure the singleton pattern is one option

south dagger
wintry quarry
amber spruce
#

alright thanks

rich adder
south dagger
rich adder
south dagger
uncut shoal
#
void generateTiles()
{
    tiles = new List<TileThing>();

    foreach (var element in elementRegister)
    {
        if (element.elementType == ElementType.Floor)
        {
            foreach (var sprite in element.floorElement.sprite.sprites)
            {
                UnityEngine.Tilemaps.Tile tile = (UnityEngine.Tilemaps.Tile)UnityEngine.Tilemaps.Tile.CreateInstance("Tile");
                tile.sprite = sprite.sprite;
                tile.name = "tile-" + element.id + "-" + sprite.material;
                tiles.Add(new TileThing(element.id, sprite.material, Direction.South, tile));
            }
        }
    }
}
#

I have this function that generates tiles at runtime

#

all the needed tile types for the game

#

but for some reason when I try to draw with the tile type using settile

#

it doesn't work

#

nothing happens

south dagger
rapid zodiac
#

hello, i created a function called invincibility in another script. i wanted to use it in other script. but when i am creating refernce, it can't recognize the name of the script.

#

`using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using Unity.VisualScripting;
using UnityEngine;

public class potionscript : MonoBehaviour

{
// Start is called before the first frame update
public BIRDSCRIPT BIRDSCRIPT;
void Start()
{

}

// Update is called once per frame
void Update()
{
    
}
 private void OnTriggerEnter2D(Collider2D collision)

{
if (collision.gameObject.layer == 3)
{
invincibility();
}
}

}
`

rocky canyon
#

you probably shouldn't name the reference identical to the type

#

BIRDSCRIPT birdScript; would be a simple change to keep you and ur IDE from getting confused

wintry quarry
#

anyway you haven't even explained what your issue is

rocky canyon
#

if invincibility() is a method in ur BIRDSCRIPT
you just need to make sure its a public method.. and you can access it by using the script reference..

wintry quarry
#

but when i am creating refernce, it can't recognize the name of the script.
What does this mean exactly?

rocky canyon
#

like myBirdScriptReference.invincibility(); but im just guessing what u mean

rapid zodiac
rocky canyon
#

thats just a general rule.. regardless of ur question

rich adder
rocky canyon
south dagger
restive linden
#

and = && is or || ?

hot palm
#

|| is or

restive linden
#

ty

hot palm
#

== is equal to

gilded sinew
#

hey guys i need quick help. i know there is a way how to separate reference groups in inspector by typing some stuff in script between groups of variables

#

can you remind me how is that done? saw it somewhere but forgot

gilded sinew
#

thank you so much šŸ™‚

rocky canyon
gilded sinew
#

thanks bud, i just need simple separation, tho i will save this link in case i want to make it better šŸ™‚

hot palm
gilded sinew
#

it will make navigate through them lot easier

hot palm
#

Yep

wraith valley
#

I can`t drag and drop

wintry quarry
wraith valley
wintry quarry
#

what do you mean by "my werewolf"

#

those .asset files? Why are they .asset files and not pngs or something?

wraith valley
#

I can`t drag and drop my werewolf to animation

wintry quarry
#

where did you get those from

wraith valley
wintry quarry
#

the .asset files

wraith valley
#

From site

hot palm
#

You can make a sprite sheet and set it as a child of the animator component

wintry quarry
hot palm
#

Or if you drag a sprite sheet into the scene view, it automatically creates an animation

south sky
#

Yo guys, does the OnCollisionStay2D act like an update function?

wintry quarry
#

Update runs every frame

rich adder
#

not even close

wintry quarry
#

OnCollisionStay runs every physics simulation step while the collision is happening

rich adder
#

closest would be fixedupdate

wraith valley
wintry quarry
#

and why you're not just using normal image files

#

or a spritesheet

wraith valley
wintry quarry
#

yes those are sprite assets

#

it looks like you dragged them into the folder for some reason

#

don't do that

south sky
wintry quarry
#

drag them directly into the scrubsheet

wintry quarry
wraith valley
#

I don`t how

wraith valley
#

But i did that

wintry quarry
#

what part is confusing you?

south sky
hot palm
wintry quarry
#

it's more performant because it doesn't allocated any managed C# memory which will need to be garbage collected later.

#

when you do .tag a new String object has to be allocated in managed memory

polar acorn
polar acorn
#

So, if you accidentally typed "Dogenemy", it'd tell you there's no such tag as "Dogenemy" and you could see that and be like "Ah, I mistyped it"

south sky
#

Free debugging

#

Bet

#

Thanks

hot palm
#

Do I have to use a hold interaction if I want to check if a button is held down? action.performed triggers only once, just like started

wintry quarry
hot palm
#

Oh didn't realize there is a specific channel, lets move there then

abstract monolith
abstract monolith
#

nope

#

i was with the orginal code but i just took the code it suggested

#

i can send the orginal code

polar acorn
abstract monolith
#

oohhh okay i see now

rocky canyon
#

interesting.. lol

polar acorn
abstract monolith
#

lol

polar acorn
#

Top one: You have a script component on something with no scripts attached. Chances are it's related to the second: PlayerMotor is not a component. It should be in its own file and it should keep the : MonoBehaviour that a new script comes with

#

Third error is the second error again. Fourth error is that you've got a negative scaled object with a collider which won't break things but might behave incorrectly.
Fifth error is proably nothing to worry about at the moment but you might need to address if you want to use the debugger

wraith valley
#

Why does the werewolf fall?

polar acorn
rocky canyon
#

this lol

wraith valley
#

I have collider

rocky canyon
#

Rigidbody's be physics objects

#

does the floor also have one?

wraith valley
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BlackWerewolfController : MonoBehaviour
{
    public float speed = 10;
    public float jumpForce = 5;
    public float h = 0;
    private Rigidbody2D rb2d;


    // Start is called before the first frame update
    void Start()
    {
        rb2d = GetComponent<Rigidbody2D>();
        
    }

    // Update is called once per frame
    void Update()
    {
        if (h != null)
        {
            
            h = Input.GetAxis("Horizontal");
            Vector3 movement = new Vector3(h, transform.position.y, transform.position.z) * speed * Time.deltaTime;
            transform.position += movement;
            if(h >= 0.1)
            {
                GetComponent<SpriteRenderer>().flipX = false;
            }
            if (h <= -0.1)
            {
                GetComponent<SpriteRenderer>().flipX = true;
            }
        }
    }
}
rocky canyon
#

ur collider looks like it may be inside the floor when it starts

#

lift it up above it some more and try again

abstract monolith
#

i cant figure this out

polar acorn
abstract monolith
#

why this so hard lol

wraith valley
polar acorn
polar acorn
#

If those are ever not zero, they're going to double every frame

wraith valley
#

They are 0

polar acorn
#

And since the rigidbody causes a change in position, you get a smidge of downward motion and your teleportation take it from there and wombo combo until infinite

polar acorn
#

But look at the inspector while playing

#

Do they stay at 0, 0?

wraith valley
#

No

#

Y position always changing

polar acorn
rocky canyon
#

exactly

abstract monolith
#

i did it guys

wraith valley
#

I fixed that

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

public class BlackWerewolfController : MonoBehaviour
{
    public float speed = 10;
    public float jumpForce = 5;
    public float h = 0;
    private Rigidbody2D rb2d;


    // Start is called before the first frame update
    void Start()
    {
        rb2d = GetComponent<Rigidbody2D>();
        
    }

    // Update is called once per frame
    void Update()
    {
        if (h != null)
        {
            
            h = Input.GetAxis("Horizontal");
            Vector3 movement = Vector2.right * h * speed * Time.deltaTime;
            transform.position += movement;
            if(h >= 0.1)
            {
                GetComponent<SpriteRenderer>().flipX = false;
            }
            if (h <= -0.1)
            {
                GetComponent<SpriteRenderer>().flipX = true;
            }
        }
    }
}
abstract monolith
#

now i jsut need to figure out what i want to make the game about

wraith valley
#
using System.Collections.Generic;
using UnityEngine;

public class Camera : MonoBehaviour
{
    public Transform player;
    

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

    // Update is called once per frame
    void Update()
    {
        if (player != null)
        {
            Vector3 player = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y);
        }
    }
}
#

The camera doesn`t follow

deft grail
#

you arent moving it at all

wraith valley
#

Wait

#

Player

#

šŸ—æ

wintry quarry
deft grail
deft grail
#

to set position of something you need to get their transform then access the .position

deft grail
wraith valley
# deft grail doesnt look like it? based of the code you are posting
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Camera : MonoBehaviour
{
    public Transform player;
    public GameObject camera;

    // Start is called before the first frame update
    void Start()
    {
        Vector3 camera = transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        if (player != null)
        {
            Vector3 camera = new Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z);
        }
    }
}
deft grail
#

thats just the first 3 lines of code

#

and it makes no sense

#

i dont need to comment on the rest

polar acorn
wraith valley
#

There`s ```cpp
player.transform.position.x

polar acorn
# wraith valley I didn`t?

Right now here is what your code actually does:
In start, you make a local variable you never use that ceases to exist when the function ends.
In update, you make a local variable you never use that ceases to exist when the function ends.

#

That's it

eternal needle
#

are you guessing at what to write by chance? you should maybe start by following a tutorial or at least doing some c# basics

deft grail
polar acorn
#

If you want to set something's position, you need to actually, you know, set the object's position

eternal needle
#

you just happen to have a gameobject named camera, and at the same time a Vector3 named camera. These are both completely unrelated to each other

polar acorn
wraith valley
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Camera : MonoBehaviour
{
    public Transform player;
    public GameObject camera;

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

    // Update is called once per frame
    void Update()
    {
        if (player != null)
        {
            camera.transform.position = player.transform.position;
            
        }
    }
}
rocky canyon
#

aye! that makes more sense

deft grail
wraith valley
#

But i should erase the GameObject camera

wraith valley
#

Thanks

deft grail
rocky canyon
eternal needle
#

you also really shouldnt have a class named Camera, because unity has one as well

polar acorn
rocky canyon
#

but yes.. transform.position would be the same gameobject that the script Camera is attached to

wraith valley
#

I want to erase that

#
using System.Collections.Generic;
using UnityEngine;

public class Camera : MonoBehaviour
{
    public Transform player;
    

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

    // Update is called once per frame
    void Update()
    {
        if (player != null)
        {
            Vector3 vector = new Vector3(player.position.x, player.position.y, -10);

            transform.position = vector;
            
        }
    }
}
#

I need with -10

nimble wigeon
#

hey guys so im making a 2d platformer game and i got my 2d character movement from a video online and im able to move left and right but for some reason im unable to jump, can someone help me, this is my code :

summer stump
deft grail
wintry quarry
wraith valley
deft grail
wraith valley
#

But thats doesnt work

summer stump
deft grail
nimble wigeon
wintry quarry
#

double check your code vs the tutorial

nimble wigeon
summer stump
#

There are multiple ways to handle that

#

The tutorial would have had to handle it in some way

wraith valley
#

Because i`m using vector3

#

But thats doesnt work

nimble wigeon
summer stump
#

Good choice

stuck sinew
#

yo i need some help i want to that i get damge wenn i collied to an "Enemy" but it dont work can someone look over my script?

tough cave
#

How do I approach a jump? When you're only allowed to jump when youre on a ground surface? without having to use 'IsTrigger'? cuz then i fall through the ground. Do I make a second floor thats invisible that will be a trigger thats on the same location as the floor orsum?

wintry quarry
#

there are several viable approaches of course

tough cave
#

I am, but this video is using a cooldown on a jump, which I thought is weird. But alr ill find a diff one

wintry quarry
#

you can rewrite it later to remove the cooldown if you wish

#

the important part of a tutorial is understanding

#

You're not just supposed to copy it and get a working thing and turn your brain off

stuck sinew
# deft grail sure, show the code

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

public class PlayerHealth : MonoBehaviour
{
public int maxHealth = 100;
private int currentHealth;

public Slider healthSlider; // Slider für die Healthbar

void Start()
{
    currentHealth = maxHealth;

    if (healthSlider == null)
    {
        Debug.LogError("HealthSlider not assigned!");
    }
    else
    {
        healthSlider.maxValue = maxHealth; // Setze den maximalen Wert des Sliders
        UpdateHealthUI(); // Aktualisiere die Healthbar-Anzeige
    }
}

void Update()
{
    // Prüfe, ob die "H"-Taste gedrückt wurde, um Schaden zu nehmen
    if (Input.GetKeyDown(KeyCode.H))
    {
        TakeDamage(10); // Füge dem Spieler 10 Schadenspunkte zu
    }
}

void OnCollisionEnter(Collision collision)
{
    Debug.Log("Collision detected"); // Debug-Log für die Kollisionserkennung

    // Wenn der Spieler mit einem Objekt kollidiert, das den Namen "Enemy" hat
    if (collision.gameObject.name == "Enemy")
    {
        Debug.Log("Enemy collision detected"); // Debug-Log für die Kollision mit dem "Enemy"-GameObject

        // Füge dem Spieler Schaden zu
        TakeDamage(10);
    }
}

public void TakeDamage(int damage)
{
    currentHealth -= damage;
    UpdateHealthUI(); // Aktualisiere die Healthbar-Anzeige

    if (currentHealth <= 0)
    {
        Die();
    }
}

void Die()
{
    UnityEngine.SceneManagement.SceneManager.LoadScene("GameOverScene");
}

void UpdateHealthUI()
{
    if (healthSlider != null)
    {
        healthSlider.value = currentHealth; // Aktualisiere den Wert des Sliders basierend auf der aktuellen Gesundheit
    }
    else
    {
        Debug.LogWarning("HealthSlider not found for updating UI!");
    }
}

}

wintry quarry
#

good god my eyes

eternal falconBOT
wraith valley
#

I don`t know

stuck sinew
wraith valley
#

But without GameObject doesn`t work

stuck sinew
#

huh

deft grail
wraith valley
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Camera : MonoBehaviour
{
    public Transform player;
    public GameObject camera;
    

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

    // Update is called once per frame
    void Update()
    {
        if (player != null)
        {
            Vector3 vector = new Vector3(player.position.x, player.position.y, -10);

             camera.transform.position = vector;

           // camera.transform.position = player.transform.position;
            
            
        }
    }
}
wraith valley
deft grail
wraith valley
#

Yes

deft grail
#

if it doesnt work then it probably isnt

deft grail
deft grail
# stuck sinew huh

click one of the links, and paste your code then send the link here, makes it easier to read code for us

wraith valley
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Camera : MonoBehaviour
{
    public Transform player;
    
    

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

    // Update is called once per frame
    void Update()
    {
        if (player != null)
        {
            Vector3 vector = new Vector3(player.position.x, player.position.y, -10);

             transform.position = vector;

           // camera.transform.position = player.transform.position;
            
            
        }
    }
}
wintry quarry
wraith valley
wintry quarry
#

That doesn't answer the question

deft grail
#

your player i assume

wraith valley
#

The camera doesn`t follow

deft grail
#

it should be at 0

wintry quarry
#

Also why did you name your script Camera? That's a recipe for sadness

polar acorn
wraith valley
wraith valley
wintry quarry
#

the camera is not shown

#

you have the werewolf selected

rocky canyon
#

run the game.. pause it... show the player transform..

wintry quarry
#

and it's at -10

scarlet skiff
#

how does one make like a collection in code, if u have a lot of fields you wanna group, you can do like:

something
{
ur fields
}

what is that called?

rocky canyon
#

and then show the camera transform

polar acorn
#

Show the camera

wraith valley
wintry quarry
scarlet skiff
deft grail
polar acorn
#

How does that remotely make sense

wintry quarry
rocky canyon
#

lol, theres ur problem ^

stuck sinew
wraith valley
#

Working

deft grail
wraith valley
#

Thanks

stuck sinew
#

my bad wait a sec

wraith valley
#

That`s mine

spiral narwhal
#

I don't get why there's an error here:

        private void UpdateBountyHuntSubtasks(SpaceshipType defeatedShipType)
        {
            _selectedGameTaskProgress
                .SubtaskProgress
                .Where(subtaskProgress =>
                    subtaskProgress.GetScriptableObject() is BountyHuntGameSubtask_SO bountyHuntTask &&
                    bountyHuntTask.SpaceshipTypesToHunt.ContainsKey(defeatedShipType))
                .Select(bountyHuntProgress => bountyHuntProgress as BountyHuntGameSubtaskProgress)
                .ToList()
                .ForEach(bountyHuntSubtaskProgress => bountyHuntSubtaskProgress.Progress.Values[defeatedShipType]++); // <--- ERROR HERE
        }

Cannot apply indexing to an expression of type 'System.Collections.Generic.Dictionary<main.entity.Overworld.SpaceshipType,int>.ValueCollection'

wintry quarry
stuck sinew
polar acorn
deft grail
spiral narwhal
#

Hmmm. How do I just increment the value of the element at that key?

wintry quarry
nimble wigeon
#

sry to bother again but i was wondering if any knew how or had a tutorial showing how to make a 2d sprite go up ladders or stairs since i need my sprite to do so and with my current movement controller it's unable to do so, for reference this is my current scene , and this is my movement controller script,

stuck sinew
wintry quarry
polar acorn
wintry quarry
#

assuming it's a key into the dictionary and not an index into a list

deft grail
spiral narwhal
#

Ohhhh
.ForEach(bountyHuntSubtaskProgress => bountyHuntSubtaskProgress.Progress[defeatedShipType]++);, yeah that seems to work

spiral narwhal
#

At least the compiler is fine with it