#okay so like this ```public class

1 messages Β· Page 1 of 1 (latest)

formal wren
#
IEnumerator SpawnSpd()
    {
while(isCollected == false)
{
        yield return new WaitForSeconds(wait);
        Instantiate(speedPWRUP, new     Vector3(Random.Range(-10, 10), 10, 0), Quaternion.identity);
}
    }
placid condor
#

oop

#

i just did that

#
{
    public float wait;
    public bool collected;
    public GameObject speedPWRUP;
    public PlayerMovement playerMovement;

    public void Start()
    {
        collected = false;
        wait = (20);
        StartCoroutine(SpawnSpd());   

    }
    IEnumerator SpawnSpd()
    {
        while (collected == false)
        {
            yield return new WaitForSeconds(wait);
            Instantiate(speedPWRUP, new Vector3(Random.Range(-10, 10), 10, 0), Quaternion.identity);
            if (collected == true)
            {
                StopCoroutine(SpawnSpd());
                playerMovement.movementSpeed = 7;
            }
        }
    }
}```
#

i was gonna ask

#

alr lemme see if it works

hollow gazelle
placid condor
#

sagudhiasd

hollow gazelle
#

yield break will exit a coroutine

formal wren
#

Will it not exit itself if the while evaluate false ?

#

(i'm talking about my answer to them)

placid condor
#

so just without the stopCoroutine?

formal wren
#
IEnumerator SpawnSpd()
    {
        while (isCollected == false)
        {
            yield return new WaitForSeconds(wait);
            Instantiate(speedPWRUP, new Vector3(Random.Range(-10, 10), 10, 0), Quaternion.identity);
        }

        playerMovement.movementSpeed = 7;
    }
#

forgot 1 line in my previous answer

placid condor
#

yup it spawns

#

but it doesnt change movement speed hol up

formal wren
#

Yeah, I made a mistake in my first answer and only handle the spawn part.

#

As jody said, you have a to add the speed part right after exiting the while loop

placid condor
#

i did tho

#

wait

verbal harbor
#

could it in theory be something wrong in playerMovement as well?

placid condor
#

alr it doesnt print too

#

is there anything wrong with this? ``` public void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
speedPWRUP.collected = true;
Destroy(this.gameObject);
}
}
}

#

let me try to make a function in playermovement actually

verbal harbor
#

I am learning too, do not take my suggestions...more so me asking questions about the code.

placid condor
#

😭 its quite hard but i aint never gon give up

formal wren
placid condor
#

ohh

#

tysm saving this to my phone

verbal harbor
placid condor
#

i can show u both if u want

verbal harbor
#

I guess my confusion, again as a new programmer, is where are you calling anything to check from there. I see you set a bool and destroy the object, but nothing to run against the bool

formal wren
#

You're destroying the object before it modifies your player speed

long vine
#

never ever ever compare tag like this 🀯

#

just transform.CompareTag("tag")

formal wren
#

Try Destroy(this.gameObject, 1f)

#

It won't hide the object, but we'll know if it's the issue

long vine
#

== is bad 😑

placid condor
formal wren
#

Actually, even this wouldn't be enough since you could be in a frame where the coroutine is waiting and it wouldn't trigger (i mean my Destroy(x, time) )

placid condor
#

this is all very overwhelming tbh

#

this is like learning japanese

long vine
formal wren
long vine
#

its gameObject

long vine
placid condor
#

yes paleese

long vine
#

gameObject is already this.gameObject

#

this is the reference of the script

#

you don't have ot use this in your script unless you have multiple variables with the same name

formal wren
long vine
formal wren
#

The coroutine is on the spawner, which also holds the collected. The design is quite flawed actually ^^'

long vine
#

anyway, you just should provide correct code form the first time, that's how beginners will learn faster πŸ™‚

#

you're right

formal wren
#

The spawner should keep reference of what it spawn at least, no ?

#

Or the spawned object have its own logic

long vine
#

can you give me the sentence where they say what doesn't work, please?

long vine
#

I think you just have to provide all scripts that are somehow connected with your spawning

#

preudo-pseudocode is great, but I really think they have to show their full code

#

method

#

it's a prefab, yes

formal wren
#

I think we're missing speedPWRUP in the thread so here's their initial code

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

public class SpeedPWRUP : MonoBehaviour
{
    private Vector2 screenBounds;
    public int randomScore;
    public PlayerMovement playerMovement;
    public SpawnSpeedPWRUP speedPWRUP;
    void Start()
    {
        screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
    }

    void Update()
    {
        if (transform.position.y < screenBounds.y * 2)
        {
            Destroy(this.gameObject);
        }
    }
    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            speedPWRUP.collected = true;
            Destroy(this.gameObject);
        }
    }
}
long vine
#

"gameObject"

formal wren
#

I just c/c their code, stop with that xD

long vine
#

and I really don't get why you have to use unnecessary collected if it's just used within that coroutine

#

why don't you stop the coroutine a that trigger method

placid condor
#

my head is going to explode 😭

formal wren
long vine
#

🀣

#

they need a reference for that class to access collected boolean

#

so that doesn't really make a lot of sense πŸ™‚

#

they just can access that class with coroutine

#

and start it

#

which reference they need to have a reference to the coroutine?

placid condor
#

can anybody just tell me what to do and explain why i need to do that

long vine
#

@signal void and coroutine cannot be static

placid condor
#

we've been going on with this for like an hour

long vine
#

I think that's your problem here

long vine
#

!code

dusty mistBOT
#
Posting code

πŸ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

πŸ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

long vine
#

no, just give 2 full scripts in code paster

#

shouldn't be that problematic

placid condor
#

yeah it worked, i tried it before

long vine
#

you're trying to teach them without even having their scripts they should have changed by that time

placid condor
#

i referenced a function in the if statement to make the movementspeed go to 7, it printed but didnt actually change the speed

long vine
#

@placid condor it seems like you're trying to make them solve your issue, but don't have any wish to take part in solving it

#

oh, really? I am really happy you have understood that you at least need to see their code in order to help them

placid condor
#
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using UnityEngine;

public class SpawnSpeedPWRUP : MonoBehaviour
{
    public float wait;
    public bool collected;
    public GameObject speedPWRUP;
    public PlayerMovement playerMovement;

    public void Start()
    {
        collected = false;
        wait = (5);
        StartCoroutine(SpawnSpd());   

    }
    IEnumerator SpawnSpd()
    {
        while (collected == false)
        {
            yield return new WaitForSeconds(wait);
            Instantiate(speedPWRUP, new Vector3(Random.Range(-10, 10), 10, 0), Quaternion.identity);
        }
        
    }
}```
```using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpeedPWRUP : MonoBehaviour
{
    private Vector2 screenBounds;
    public int randomScore;
    public PlayerMovement playerMovement;
    public SpawnSpeedPWRUP speedPWRUP;
    void Start()
    {
        screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
    }

    void Update()
    {
        if (transform.position.y < screenBounds.y * 2)
        {
            Destroy(this.gameObject);
        }
    }
    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            speedPWRUP.collected = true;
            playerMovement.AddSPD();
            Destroy(gameObject);
        }
    }
}```
#

yeah

#

no they keep spawning

#
    {
        Debug.Log("cock");
        movementSpeed = 7;
    }``` this?
#

yes

#

but speed is not being changed

long vine
#

fuck man, where have I even mentioned you to do it

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

public class PlayerMovement : MonoBehaviour
{
    public float movementSpeed = 6;
    public float inputHorizontal;
    public float inputVertical;
    Rigidbody2D rb2D;

    public void Start()
    {
        rb2D = GetComponent<Rigidbody2D>();
    }
    public void Update()
    {
        inputHorizontal = Input.GetAxisRaw("Horizontal");
    }
    public void AddSPD()
    {
        Debug.Log("cock");
        movementSpeed = 7;
    }

    void FixedUpdate()
    {
        if (inputHorizontal != 0)
        {
            rb2D.velocity = new Vector2(inputHorizontal * movementSpeed, inputVertical);
        }
        else rb2D.velocity = new Vector2(0f, 0f);
    }
}
long vine
formal wren
#

The trigger is called, they have the log in their console

placid condor
#

aight lemme see

#

nope

#

i changed it to 50

#

still doesnt change it

long vine
#

what's even the problem?

placid condor
#

movementspeed aint changing

long vine
#

is method called?

placid condor
#

huh

signal void
#

tfw automod banned for 1 minute bc i said the debug log word too much

#

πŸ’€

long vine
#

good for you

placid condor
#

sorry whats a method again i forgot πŸ’€

formal wren
placid condor
#

yeah its printing

long vine
signal void
long vine
#

the method where movement speed is changed

placid condor
signal void
#

because to me it seems like movementSpeed should have been changing

#

theres no reason for it not to be changing

long vine
#

do you have other scripts?

signal void
#

^^^ the only reason movementSpeed would still be 6 is if its being set to 6 constantly by something else

long vine
#

or if they just don't check it

#

check movementSpeed in update

signal void
#

or in the inspector

formal wren
#

They use it in fixedUpdate, so the modification should be visual enough between 6 and 50.

placid condor
#

i was checking it throught the inspector before ill try update now

formal wren
#

But you're right, something is modifying this value elsewhere

signal void
#

only explanation

long vine
#

you are just guessing

#

it's not hard to say if you have another script that changes it

signal void
#

thats literally what we're saying

#

your 3 possibilities are:

  1. its being changed and you dont realize
  2. its being changed back to default value by something without you knowing
  3. its actually not being changed and you are being confused by an identical Debug.Log() elsewhere
long vine
formal wren
#

If you're using Visual Studio, right-click your variable and click on "find all references"

signal void
long vine
#

please

placid condor
signal void
placid condor
#

and i dont have any other debuglogs on

#

is this a unity glitch or somethin

long vine
#

can you export the package for us?

signal void
formal wren
placid condor
long vine
placid condor
#

okay dang

#

i said sure

long vine
#

in zip format

placid condor
#

it says build completed with the result of "failed" 😭

signal void
long vine
placid condor
#

i just did

#

i restarted it then tried

long vine
placid condor
#

honestly its kinda late rn

#

sorry but i gtg

#

atleast i learned somethin

long vine
#

🀣

formal wren
#

Ok ! Have a nice evening and don't hesitate to reach out when you want to pursue the debugging πŸ™‚

long vine
#

it's kinda you haven't even bother yourself to export the package

#

that's either laziness or disrespect I mean

#

anyway

formal wren
#

OK. I'll try to stay polite here, but even if you're frustrated, try to remain respectful and not assume they are lazy. They're on this problem for a few hours now, it's alright if they want to give up for now.

#

Taking a break won't hurt

long vine
#

break won't hurt for you, but I mean

#

like someone is solving my problem for quite a long time, I really won't think about making a break

#

also when somebody is waiting for my response

#

maybe it's just about me

#

also I will try to reply everyone who is trying to help me

formal wren
#

Yes, I agree. But we're also not going anywhere here. So i prefer having someone admit they're lost and their brain is not registering anything anymore. Anyway, that's not the place to talk about this.