Vector3 to Transform as a coin spawn target

Hello,

I am using the script below to spawn coins to a target Vector3. The issue arises with different screen sizes.

How to convert the target Vector3 to Transform of the target? So that different screen sizes do not represent an issue anymore?

using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.Pool;
using UnityEngine.TextCore.Text;
using UnityEngine.UI;
using static UnityEngine.GraphicsBuffer;
public class CoinController : MonoBehaviour
{
    [SerializeField] private GameObject PileOfCoinsParent;
    [SerializeField] private Text Counter;
    [SerializeField] private Vector3[] InitialPos;
    [SerializeField] private Quaternion[] InitialRotation;
    [SerializeField] private int coinsNumber;
    void Start()
    {
        InitialPos = new Vector3[coinsNumber];
        InitialRotation = new Quaternion[coinsNumber];
        for (int i = 0; i < PileOfCoinsParent.transform.childCount; i++)
        {
            InitialPos = PileOfCoinsParent.transform.GetChild(i).position;
            InitialRotation = PileOfCoinsParent.transform.GetChild(i).rotation;
        }
    }
    private void Reset()
    {
        for (int i = 0; i < PileOfCoinsParent.transform.childCount; i++)
        {
            PileOfCoinsParent.transform.GetChild(i).position = InitialPos;
            PileOfCoinsParent.transform.GetChild(i).rotation = InitialRotation;
        }
    }
    public void SpawnCoins( int coinsNumber)
    {
        Reset();
        var delay = 1f;
        PileOfCoinsParent.SetActive(true);
        for (int i = 0; i < PileOfCoinsParent.transform.childCount; i++)
        {
            PileOfCoinsParent.transform.GetChild(i).DOScale(endValue: .8f, duration: 0.3f).SetDelay(delay).SetEase(Ease.OutBack);
            PileOfCoinsParent.transform.GetChild(i). GetComponent<RectTransform>().DOAnchorPos(endValue: new Vector2(-386f, 493f), .5f).SetDelay(delay +.5f).SetEase(Ease.OutBack);
            PileOfCoinsParent.transform.GetChild(i).DORotate(Vector3.zero, .5f).SetDelay(delay + .5f).SetEase(Ease.Flash);
            PileOfCoinsParent.transform.GetChild(i).DOScale(endValue: 0f, duration: 0.3f).SetDelay(delay + 1.8f).SetEase(Ease.OutBack);
            delay += 0.1f;
        }
    }
}

Use code tags when posting code. The text formatting got messed up because you didn’t use code tags.

if you show me how to do it, i will edit. thanks

The page I linked shows how to do it. That’s why I linked it.

resolved by purchsing this asset. Collecting Effect | Particles/Effects | Unity Asset Store

that was a waste of money, this is really a simple issue to resolve without spending cash

1 Like

Thanks I just didn’t know how :slight_smile:

You waited less than three hours before buying this asset and your most recent post before then. If you can’t either work the solution out on your own or be patient enough to wait for help, you’re going to run into way bigger problems down the line that will either get very expensive very fast or stop you dead in your tracks. On top of that, because this is such a basic problem, you should have posted it in the beginner section, “Getting Started,” not "General Discussion.

2 Likes

Next time I suggest waiting at least 1 day, before buying something. I would have happily helped you resolve this issue, but you had already bought something by the time I saw this thread.

As @Murgilod said, 3 hours is just not a sensible timeframe to wait before buying something, unless you are rich and made of money in which case buy everything you want. But ideally you should be as frugal as possible in game development.

24 hours to get a resolution to an issue is really the bare minimum if you are posting on a public forum, and that in the future is how long you should wait.

1 Like