void Update() { if (currentState == GiftState.IDLE && !rigidBody.IsSleeping()) { ForceSleep(); } if (currentState == GiftState.COLLISIONING && !Input.GetMouseButton(0) && rigidBody.IsSleeping()) { if (canSleep) { currentState = GiftState.SLEEPING; } } }
public void Initialize(SpriteAtlas spriteAtlas, bool canSleep = true) { this.canSleep = canSleep; currentState = GiftState.IDLE; var defaultEyeSprite = spriteAtlas.GetSprite(EyeSpriteType[0]); var defaultMouthSprite = spriteAtlas.GetSprite(MouthSpriteType[0]); var randomBodySpriteName = BodySpriteType[Random.Range(0, BodySpriteType.Length - 1)]; Body.sprite = spriteAtlas.GetSprite(randomBodySpriteName); Ribbon.sprite = spriteAtlas.GetSprite(GetCorrespondingRibbon(randomBodySpriteName)); LeftEye.sprite = defaultEyeSprite; RightEye.sprite = defaultEyeSprite; Mouth.sprite = defaultMouthSprite; var randomScale = Random.Range(Config.MIN_GIFT_SCALE_SIZE, Config.MAX_GIFT_SCALE_SIZE); transform.localScale *= randomScale; rigidBody.mass *= randomScale; }
public void Select() { currentState = GiftState.SELECTED; }
public void OnCollisionEnter2D(Collision2D collision) { currentState = GiftState.COLLISIONING; }