Galaxy Anpassen
This commit is contained in:
94
Assets/PlanetUI.cs
Normal file
94
Assets/PlanetUI.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
|
||||
|
||||
public class PlanetUI : MonoBehaviour
|
||||
{
|
||||
|
||||
public float rotationSpeed = 1f; // Geschwindigkeit der Rotation
|
||||
public float radius = 5f; // Radius des Kreises
|
||||
private float angle = 0f; // Aktueller Winkel im Kreis
|
||||
private Vector2 centerPosition; // Position des Zentrums des Kreises
|
||||
|
||||
public Text textID;
|
||||
|
||||
public int PlayerID = 0;
|
||||
|
||||
// Planet values
|
||||
public int money;
|
||||
public int science;
|
||||
public int power;
|
||||
public int food;
|
||||
public int industrialCapacity;
|
||||
public int population;
|
||||
public int actualFood;
|
||||
private int OldFoodLevel = 0;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
System.Random random = new System.Random();
|
||||
centerPosition = transform.parent.position; // Position des Zentrums
|
||||
transform.position = GetPositionOnCircle(angle); // Setze die Startposition
|
||||
food = random.Next(2, 5); // Generiert eine zuf<75>llige Zahl zwischen 2 (inklusive) und 5 (exklusive)
|
||||
science = random.Next(2, 5);
|
||||
money = random.Next(2, 5);
|
||||
industrialCapacity = random.Next(2, 5);
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
angle += rotationSpeed * Time.deltaTime; // Aktualisiere den Winkel basierend auf der Geschwindigkeit
|
||||
transform.position = GetPositionOnCircle(angle); // Berechne die neue Position des Planeten
|
||||
if (PlayerID == 0)
|
||||
{
|
||||
textID.text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
textID.text = PlayerID.ToString();
|
||||
}
|
||||
DistributeFoodToPopulation();
|
||||
}
|
||||
|
||||
Vector3 GetPositionOnCircle(float angle)
|
||||
{
|
||||
float xPos = centerPosition.x + Mathf.Sin(angle) * radius; // X-Position auf dem Kreis
|
||||
float yPos = centerPosition.y + Mathf.Cos(angle) * radius; // Y-Position auf dem Kreis
|
||||
return new Vector3(xPos, yPos, 0f); // Position als Vektor zur<75>ckgeben
|
||||
}
|
||||
|
||||
public void DistributeFoodToPopulation()
|
||||
{
|
||||
int remainingFood = food - population;
|
||||
|
||||
if (remainingFood < 0)
|
||||
{
|
||||
// Falls das Essen nicht ausreicht, um die Ver<65>ffentlichung zu decken,
|
||||
// setze actualfood auf 0 und aktualisiere die publication entsprechend
|
||||
actualFood = 0;
|
||||
population = food;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Falls das Essen ausreicht, um die Ver<65>ffentlichung zu decken,
|
||||
// setze actualfood auf den <20>bersch<63>ssigen Wert
|
||||
actualFood = remainingFood;
|
||||
}
|
||||
}
|
||||
// update scourse methodes
|
||||
// nur Food
|
||||
public void UpdateFood(int foodLevel)
|
||||
{
|
||||
if (foodLevel > OldFoodLevel)
|
||||
{
|
||||
food *= foodLevel;
|
||||
OldFoodLevel = foodLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user