0% found this document useful (0 votes)
2 views1 page

sample

The script RandomizeStartPositions in Unity randomizes the vertical positions of an array of marble GameObjects within a specified range at the start of the game. It also instantiates name tags for each marble, setting their names based on a MarbleNameManager and ensuring the tags are oriented towards the camera. In the Update method, it adjusts the weights of the target group based on the marbles' positions to influence camera behavior.

Uploaded by

ovidiua2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

sample

The script RandomizeStartPositions in Unity randomizes the vertical positions of an array of marble GameObjects within a specified range at the start of the game. It also instantiates name tags for each marble, setting their names based on a MarbleNameManager and ensuring the tags are oriented towards the camera. In the Update method, it adjusts the weights of the target group based on the marbles' positions to influence camera behavior.

Uploaded by

ovidiua2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using UnityEngine;

using Unity.Cinemachine;
using System;

public class RandomizeStartPositions : MonoBehaviour


{
public GameObject[] marbles; // Drag your marbles here in the Inspector
public Transform[] marblesForNames;
public float yOffsetRange = 1f; // Max offset amount for Y axis
[SerializeField] public CinemachineTargetGroup targetGroup;
public GameObject nameTagPrefab;

void Start()
{
foreach (GameObject marble in marbles)
{
Vector3 pos = marble.transform.position;
float randomY = UnityEngine.Random.Range(-yOffsetRange, yOffsetRange);
marble.transform.position = new Vector3(pos.x, pos.y + randomY, pos.z);
}

for (int i = 0; i < marblesForNames.Length; i++)


{
GameObject tag = Instantiate(nameTagPrefab);

var tagScript = tag.GetComponent<Billboard>();


if (tagScript != null && MarbleNameManager.marbleNames != null && i <
MarbleNameManager.marbleNames.Length)
{
tag.GetComponent<Billboard>().marble = marblesForNames[i];
Canvas canvas = tag.GetComponentInChildren<Canvas>();
if (canvas != null)
{
canvas.worldCamera = Camera.main;
}
tagScript.SetName(MarbleNameManager.marbleNames[i]);
}
}
}

void Update()
{
for (int i = 0; i < targetGroup.m_Targets.Length; i++)
{
float xPos = marbles[i].transform.position.x;
float yPos = marbles[i].transform.position.y;
targetGroup.m_Targets[i].Weight = Math.Abs(xPos) + Math.Abs(yPos);
}
}
}

You might also like