#Thread

1 messages · Page 1 of 1 (latest)

tender rivet
#

OK so I think you're a bit confused on what the components should be attached to

#

OnTriggerEnter OncollisionEnter etc are for when you have both the script attached to the GameObject AND a collider of some sorts, like a BoxCollider

#

Yes, that is what you want to do

#

but you originally had it on the text GameObject not the player

#

yes, but that script was attached to the text gameobject, not the player like it should of been

#

AS shown here:

#

It wont trigger because there is no collider

#

again, like I said it needs both to function, a collider and a script listening for the collision (like OnTriggerEnter)

#

most likely yes. So long as ChangeScoreText is called in the OnTriggerEnter2D method

#

yes

#

Does the player need to like stand on it or something? If not, set the collider to trigger and change the OnCollisionEnter2D to OnTriggerEnter2D

#

a trigger sounds like it would be better

#

wait

#

platform? does the player need to stand on the playform?

#

did you change the collider in the inspector to be a trigger?

#

yeah 2D evnironment, so OnTriggerEnter2D

#

not OnTriggerEnter

#

aye, that wont work haha

#

so is everything working now?

#

can you paste the error message?

#

yeah that's why I asked if the player can stand on it, so in this case OnCollisionEnter2D is required

#

To me it looks like its working correctly

#

yeah, that was a double collision

#

no, I mean the cube spinning hit the platform twice

#

one corner then quickly the next

#

ok so something I want you to test first is against double collisions.

in the code you provivded:

   private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "CanJumpOn")
        {
            ChangeScoreText();
            Score += 1;
        }
    }

change it to:

   private void OnCollisionEnter2D(Collision2D collision)
    {
        int currentPlatformId = collision.gameObject.GetInstanceID();

        if (collision.gameObject.tag == "CanJumpOn" &&  currentPlatformId != lastPlatformId)
        {
            ChangeScoreText();
            Score += 1;
            lastPlatformId = currentPlatformId;
        }
    }

Somewhere in the class add a field int lastPlatformId;

#

that prevents the scenario of the player jumping on the same platform twice, and gaining points twice

#

?

#

its a method call, not a property

#

oh, sorry it's collision.gameObject.GetInstanceID()

#

yes

#

what are the values after 4? the video only went up to the 3rd platform

#

wait, is the score script attached to the platforms or the player?

#

can you provide the entire script

#

Set Score to -1

[Header("Score")]
    public float Score = -1;
    public Text ScoreText;
    int lastPlatformId;
#

also, call Score += 1 before ChangeScoreText()

#

does it reflect it in the inspector? changing it from 0 to -1 in code wont update the script, unless it's newly added script to a GameObject

#

like, the value that starts, is it still 0 or -1?

#

that says -1 right?

#

ok

#

alright

#

still not sure why 3 is skipped

#

yeah was gunna say, there might be two of them

#

no, leave it as it will prevent double increments of your score

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

public class GeneratePlatforms : MonoBehaviour
{
    public float SpawnTime;
    public float YMin, YMax;
    public float ChangeX = 8f;

    public GameObject Platform;

    public Vector3 nextPlatformPosition;

    void Start()
    {
        PlatformSpawn();
        StartCoroutine("MoveCloner");
    }

    void PlatformSpawn()
    {
       Instantiate(Platform, nextPlatformPosition, Quaternion.identity);

       float y = Random.Range(YMin, YMax);
       nextPlatformPosition = new Vector3(nextPlatformPosition.x + ChangeX, y, 0f);
    }

    IEnumerator MoveCloner()
    {
        while (true)
        {
            yield return new WaitForSeconds(1);

            PlatformSpawn();
        }
    }
}
#

set nextPlatformPosition to the starting position you want

#

yes

#

it will increment it from there after the first spawn

#

also, I edited the above script to include a PlatformSpawn() call so you dont have a delay of 1 second before the first one spawns

#

oh, no you do that in the inspector

#

if you really want to set it by code, you need to do new Vector3(26.2f, 0, -1) not 26.2, 0, -1

#

sorry forgot the f

#

26.2f

#

you can, but its mandatory on any value with a decimal point

#

oh lord I completely overlooked that lmao one sec

#

nextPlatformPosition += new Vector3(ChangeX, y, 0f);
change it to:
nextPlatformPosition = new Vector3(nextPlatformPosition.x + ChangeX, y, 0f);

#

I tested the script on my end and it works fine

#

oh, it's all zero

#

Make the platforms a prefab, and delete the platforms in the scene

#

it will turn blue if its a prefab

#

yes, all platforms other than the starting one

#

and by starting i mean the one the player spawns on top of

#

yes

#

the prefab must not be setup correctly

#

make sure it is setup how you want it to be instantiated, including if it is active or not

#

needs to be checked, else it spawns invisible and not active in scene

#

lazy lol

#

it can be anything, that is the default

#

set the material you have it spawn with

#

screenshot the prefab and it's components

#

that one is likely still in the scene, you need to delete it and have only the ones spawned by the GeneratePlatforms script active

#

screenshot your Hierarchy

#

is that the starting platform?

#

are you sure you didnt accidently add any platforms?

#

other than the starting one

#

What does the platform cloner have

#

mind doing a video of it happening?

#

that's so weird

#

what does it look like when you play it while viewing the scene?

#

not game view

#

oh yeah then this is a visuals thing

#

not something with the script

#

have you tried adjusting any of the post processing your doing? I noticed the screen is slightly warped

#

could you try disabling it temporarily to see if it fixes it?

#

how do you produce a white background?

#

set it to skybox and see if that fixes it

#

temporarily

#

so the first one literally just doesnt render at all?

#

wtf that makes no sense

#

its clearly visible in scene view

#

could you try disabling the PlatformSpawn() that happens in start? just comment it out. I think spawned too soon

#
    void Start () {
       // PlatformSpawn();
        StartCoroutine("MoveCloner");
    }
#

like that

#

can you delete that camera component and add a new one

#

and dont change a single setting

#

leave it out for now

#

Im at a loss

#

Something you could try is to create a new scene, with new everything. But just add only the scripts, camera, and the new platform prefabs

#

and pray that it works

#

lmao

#

Im thinking that there's something overlayed at that specific spot that is hiding the first platform

#

Can you show me what ScoreUI looks like

#

in the inspector disable everything but the platform1 EventSystem Player PlatformCloner and Camera

#

OK I personally want to look into this. right click the Assets folder and select Show in explorer

#

zip the Assets folder and send me the files

#

had to creat a new project lol

#

sec

#

can you zip me the projectSettings folder as well

#

did you setup the project as a 2D URP?

#

k

#

sorry had to install a new editor

#

2022 was giving me weird issues

#

yeah

#

finised downloading

#

I honestly cant seem to find an issue

#

sounds like a plan