I’m creating a game where the player can put 4 objects in any combination, even 4 of itself. What would be the best method of going about this, and letting the game cycle through the list the player created based on a timer.
Example: The player has 4 weapons: Katana, Axe, Spear, Chakram. The player can set the order to Chakram, Chakram, Katana, Spear. The game will give the player the item based on the order of the list they set. The game will only give the player an item after a set amount of time.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Runner : MonoBehaviour
{
private Touch _touch;
private Rigidbody _rb;
private Animator _anim;
private UIManager _ui;
(SerializeField) private HealthBar _healthBar;
(SerializeField) private Bullet _bullet;
(SerializeField) private float _moveSpeed = 0.25f;
(SerializeField) private float _dashSpeed = 0.5f;
(SerializeField) private int _health = 20;
(SerializeField) private int _currentHealth;
(SerializeField) private bool _hasZwei;
(SerializeField) private bool _hasAxe;
(SerializeField) private bool _hasDagger;
(SerializeField) private bool _hasKatana;
void Start()
{
_rb = GetComponent<Rigidbody>(); //Accessing the Rigidbody Component
_anim = GetComponent<Animator>(); //Accessing the Animator Component
_ui = GameObject.Find("UI Manager").GetComponent<UIManager>(); //Accessing the UI Manager Component
_currentHealth = _health;
_healthBar.SetMaxHealth(_health);
_anim.SetBool("Running",true);
}
// Update is called once per frame
void FixedUpdate()
{
Movement();
}
void Update()
{
Invoke("GainPowerUp", 5f);
}
void Movement()
{
if (Input.touchCount > 0)
{
_touch = Input.GetTouch(0);
if (_touch.phase == TouchPhase.Moved)
{
_rb.MovePosition( new Vector3(
transform.position.x + _touch.deltaPosition.x * _moveSpeed,
transform.position.y,
transform.position.z + _touch.deltaPosition.y * _moveSpeed));
_rb.constraints = RigidbodyConstraints.FreezeRotation;
}
}
if (Input.touchCount == 2)
{
_touch = Input.GetTouch(1);
switch(_touch.phase)
{
case TouchPhase.Began:
if (_hasAxe == false && _hasZwei == false && _hasKatana == false && _hasDagger == false)
{
Debug.Log("Has no weapon.");
}
if(_hasZwei)
{
Debug.Log("Player has attacked with Zweihander");
_hasZwei = false;
_anim.SetTrigger("NoWeapon");
}
if(_hasAxe)
{
Debug.Log("Player has attacked with Axe");
_hasAxe = false;
_anim.SetTrigger("NoWeapon");
}
if(_hasDagger)
{
Debug.Log("Player has attacked with Dagger");
_hasDagger = false;
_anim.SetTrigger("NoWeapon");
}
if(_hasKatana)
{
Debug.Log("Player has attacked with Katana");
_hasKatana = false;
_anim.SetTrigger("NoWeapon");
}
break;
}
}
}
public void Damage(int damage)
{
_currentHealth -= damage;
_healthBar.SetHealth(_currentHealth);
if (_currentHealth == 0)
{
gameObject.SetActive(false);
}
}
public void GainPowerUp(int _powerUp)
{
_powerUp = Random.Range(0,4);
switch(_powerUp)
{
case 1:
//Sword Powerup
_hasZwei = true;
_hasAxe = false;
_hasDagger = false;
_hasKatana = false;
_anim.SetTrigger("SwordRun");
break;
case 2:
//Axe Powerup
_hasAxe = true;
_hasZwei = false;
_hasDagger = false;
_hasKatana = false;
_anim.SetTrigger("AxeRun");
break;
case 3:
//Katana Powerup
_hasKatana = true;
_hasAxe = false;
_hasDagger = false;
_hasZwei = false;
_anim.SetTrigger("KatanaRun");
break;
case 4:
//Dagger Powerup
_hasDagger = true;
_hasAxe = false;
_hasKatana = false;
_hasZwei = false;
_anim.SetTrigger("DaggerRun");
break;
}
}
}