#What if

1 messages · Page 1 of 1 (latest)

bleak oxide
#

What is it doing and what do you want it to do?

shrewd nimbus
#

ok so

#

its doing nothing

#

and i want to switch tag from gamer to ded

#

once it touches

#

this object'

#
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;

public class atak : MonoBehaviour
{
    public GameObject objectToDuplicate;
    private bool hasBeenDuplicated = false;
    public float someCooldown;
    private float number = Mathf.Infinity;
    [SerializeField] private float distance = -3;
    public GameObject gameoverscreen;
    public GameObject dude;

    void Update()
    {
        number += Time.deltaTime;
        if (number > someCooldown)
        {
            GameObject susiObject = Instantiate(objectToDuplicate, transform.position, transform.rotation);
            Rigidbody2D susiRigidbody = susiObject.GetComponent<Rigidbody2D>();
            susiRigidbody.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
            susiRigidbody.velocity = new Vector2(0.0f, distance);
            number = 0;
        }

        if (dude.gameObject.CompareTag("ded"))
        {
            gameoverscreen.SetActive(true);
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (dude.CompareTag("gamer"))
        {
            dude.tag = "ded";
        }
    }
} //dude```
#

full script

tired compass
#

how about an bool isDed on the dude instead of swapping tags around

shrewd nimbus
#

this is script thats inside duplicating object

bleak oxide
#

I'd second something like that

bleak oxide
#

Also, I'd try throwing in some logs to 1) see where in the code it's actually getting to, and 2) to see what the code is actually changing

shrewd nimbus
#
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;

public class atak : MonoBehaviour
{
    public GameObject objectToDuplicate;
    private bool hasBeenDuplicated = false;
    public float someCooldown;
    private float number = Mathf.Infinity;
    [SerializeField] private float distance = -3;
    public GameObject gameoverscreen;
    public GameObject dude;
    public bool dang = false;

    void Update()
    {
        number += Time.deltaTime;
        if (number > someCooldown)
        {
            GameObject susiObject = Instantiate(objectToDuplicate, transform.position, transform.rotation);
            Rigidbody2D susiRigidbody = susiObject.GetComponent<Rigidbody2D>();
            susiRigidbody.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
            susiRigidbody.velocity = new Vector2(0.0f, distance);
            number = 0;
        }

        if (dang == true)
        {
            gameoverscreen.SetActive(true);
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (dang == false)
        {
            dang = true;
        }
    }
} //dude```
shrewd nimbus
#

like

#

when i change dang to true in test mode

#

game over screen appears

#

but when i touch the object that has trigger inside it

#

it doesnt execute if command

#

prefab has a trigger

#

code isnt wrong so what could be wrong here

bleak oxide
shrewd nimbus
#

yes

#

could this be the mistake

#

what

#

wait a sec

#

i think i got it

bleak oxide
#

I'm not seeing in the inspector where you're changing it

shrewd nimbus
#

yes

#

cuz its not changed rn

#

do u want me to show u that

bleak oxide
#

Oh I thought that's what you were trying to show in the screenshot

#

But I see now it was part of your second message

shrewd nimbus
#

yeah

#

im tryng something rn

#

it might work

bleak oxide
#

Alrighty. Let me know how it goes

shrewd nimbus
#

oh

#

it didnt work

shrewd nimbus
#

so i removed prefab and made it dupe a gameobject

#

it did fix it

#

now colliders are inside those objects itself

#

but

#

still when colliding its not working

bleak oxide
#

I'm guessing the properties you're modifying are not the ones for the instance of the prefab

shrewd nimbus
#

WAIT
I

#

I KNOW

bleak oxide
#

What's up?

shrewd nimbus
#

i see now

#

the

#

im duping object with another script

#

not inside the object

#

and i need to touch empty game object

#

to do that command

#

i need to create on trigger script inside object that is gettig duped

#

thanks for help by the way