HeavenStudio/Assets/Scripts/Games/Spaceball/SpaceballPlayer.cs
Slaith ebeea121ed Moved all minigame initialization to Awake()
I just moved everything that was in start to awake. There are a few other changes I made, like using init functions rather than awake in scripts that depended on something that was initialized in another script's awake (to make sure things always happen in the right order), as well as some other stuff in some specific minigames
2022-03-25 19:08:46 -07:00

70 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_Spaceball
{
public class SpaceballPlayer : MonoBehaviour
{
private Animator anim;
private int currentHitInList = 0;
public int costume;
public SpriteRenderer PlayerSprite;
public List<SpriteSheet> PlayerSpriteSheets = new List<SpriteSheet>();
[System.Serializable]
public class SpriteSheet
{
public List<Sprite> sprites;
}
public static SpaceballPlayer instance { get; set; }
private void Awake()
{
instance = this;
anim = GetComponent<Animator>();
}
private void Update()
{
if (Spaceball.instance.EligibleHits.Count == 0)
currentHitInList = 0;
if (PlayerInput.Pressed())
{
Swing(null);
}
}
public void SetCostume(int costume)
{
this.costume = costume;
anim.Play("Idle", 0, 0);
}
public void Swing(SpaceballBall b)
{
if (b == null)
{
Jukebox.PlayOneShotGame("spaceball/swing");
}
else
{
}
anim.Play("Swing", 0, 0);
}
public void SetSprite(int id)
{
PlayerSprite.sprite = PlayerSpriteSheets[costume].sprites[id];
}
}
}