corn sprite設定

This commit is contained in:
kimura 2021-06-24 10:01:04 +09:00
parent a1c12b6e33
commit b6dec2d6a3
2 changed files with 12 additions and 8 deletions

View File

@ -7,8 +7,9 @@ using Random = UnityEngine.Random;
[RequireComponent(typeof(Rigidbody2D))]
public class Corn : MonoBehaviour
{
// [SerializeField] private List<Sprite> cornSprites;
[SerializeField] private Sprite cornSeedSprite;
[SerializeField] private Sprite cornSimpleSprite;
[SerializeField] private Sprite cornBurntSprite;
// コーン速度
[SerializeField] private float cornVelocity;
// コーンがスポーンしてからの時間
@ -27,27 +28,28 @@ public class Corn : MonoBehaviour
void Start()
{
rigidbody2D = GetComponent<Rigidbody2D>();
// GetComponent<SpriteRenderer>().sprite = cornSeedSprite;
cornSpawnTime = Time.time;
var cornPopBasicTime = 5f;
cornPopTime = cornPopBasicTime + Random.Range(0, 5f);
rigidbody2D.position = new Vector2(0f, Random.value);
}
private void Update()
{
cornVelocity = rigidbody2D.velocity.magnitude;
cornLifeTime = Time.time - cornSpawnTime;
if (!isPop && cornLifeTime >= cornPopTime)
{
CornPop();
isPop = true;
}
// if (!isPop && cornLifeTime >= cornPopTime)
// {
// CornPop();
// isPop = true;
// }
}
private void CornPop()
{
var popVelocity = 20f;
var popDirection = new Vector2(Random.value * 2 - 1, Random.value * 2 - 1);
Debug.Log(popDirection);
rigidbody2D.AddForce(popVelocity * popDirection, ForceMode2D.Impulse);
GetComponent<SpriteRenderer>().sprite = cornSimpleSprite;
}

View File

@ -46,7 +46,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 175dce409df2f4d3aa1941a08822e03e, type: 3}
m_Name:
m_EditorClassIdentifier:
cornSimpleSprite: {fileID: 21300000, guid: 97ac0328246620745b8881e07f709ce7, type: 3}
cornSeedSprite: {fileID: 21300000, guid: 97ac0328246620745b8881e07f709ce7, type: 3}
cornSimpleSprite: {fileID: 21300000, guid: 041ad2539ff56d945ab2da4be6a02f04, type: 3}
cornBurntSprite: {fileID: 21300000, guid: a9d669186411b2b4da1511f59a91b4c9, type: 3}
cornVelocity: 0
cornLifeTime: 0
--- !u!212 &1324329073609281163