0
\$\begingroup\$

When im breaking fence GameObject there should pop up scores, so it works fine. But position of pop up scores is too low, im trying to raise it by Vector3 offset on y axis, but it doesn't work. Pop up scores GameObject is spawning on the field as a child of destroyed object before fence GameObject was destroyed, so that why im using transform.localPosition instead of transform.position, but I tried everything and it doesnt work at all.

enter image description here

There is confirmation that scores GameObject is child of fence GameObject:

enter image description here

Code for destructible object:

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

public class FenceCollision : MonoBehaviour
{
    public Animator fenceAnim;
    public GameObject popUp;

    public void Start()
    {
        fenceAnim = GetComponent<Animator>();

    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("pla"))
        {
            ShowFloatingText();
            ScoresManager.scores += 10;
            fenceAnim.Play("BlockBroke");
            Destroy(gameObject, 0.17f);
        }
    }

    public void ShowFloatingText()
    {
        Instantiate(popUp, transform.position, Quaternion.identity, transform);
    }
}

Code for pop up scores object:

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

public class PopUpText : MonoBehaviour
{
    public float destroyTime = 2f;
    public Vector3 offset = new Vector3(0, 2f, 0);

    void Start()
    {
        transform.localPosition += offset;
        Destroy(gameObject, destroyTime);
    }
}
```
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. \$\endgroup\$
    – liggiorgio
    Jan 21, 2022 at 17:26
  • \$\begingroup\$ @liggiorgio I mentioned everything in the topic. If you need details ok. Imagine, I have a 2d sprite(fence), when player hits it, that object should be destroyed in 0.17 seconds, and there should pop up scores as you can see on the picture I have scores at the bottom of sprite, I need increase offset on y axis to move it a little bit up. \$\endgroup\$
    – Silz
    Jan 22, 2022 at 12:50

0

You must log in to answer this question.

Browse other questions tagged .