๋Œ€์ถฉ ๊ฐ„๋‹จํ•˜๊ฒŒ ์งฌํ‘ธ๊ฒŒ์ž„ ๋งŒ๋“ค๊ณ  ์žˆ๋Š”๋ฐ


๋˜‘๊ฐ™์€ ๋ชฌ์Šคํ„ฐ ์˜ค๋ธŒ์ ํŠธ 3๊ฐœ๋ฅผ ๋งต์ƒ์— ๋ฐฐ์น˜ํ–ˆ๋”๋‹ˆ(ํ•ด๋‹น ๋ชฌ์Šคํ„ฐ๋Š” ๋ฌด์  ์ƒํƒœ์ผ๋•Œ ๋ถ€๋”ชํžˆ๋ฉด ๋‚ ๋ผ๊ฐ€๋Š” ๊ธฐ๋Šฅ์ด ์žˆ์Œ)


๋งจ ์ฒ˜์Œ ๋ชฌ์Šคํ„ฐ์— ์ ‘์ด‰ํ–ˆ์„๋•Œ ๋’ค์— 2 ๋งˆ๋ฆฌ๋„ ๋™์‹œ์— ๊ฐ™์ด ๋‚ ๋ผ๊ฐ€๋Š”๋ฐ ์ด๊ฑฐ ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•ด์•ผํ• ๊นŒ...


๋ชฌ์Šคํ„ฐ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํ”„๋ฆฌํŒนํ™” ์‹œ์ผœ์„œ ๋ณต์‚ฌํ•ด์„œ ์“ฐ๊ธด ํ–ˆ๋Š”๋ฐ ์ด๊ฒŒ ๋ฌธ์ œ์ผ๊นŒ..?




public class Monster : MonoBehaviour

{

private SpriteRenderer spriteRenderer;

private float rotationSpeed = 1000f;

public int speed = 3;

public float leftPos;

public float rightPos;

public GameObject originalPosObj;

Transform originalPos;

public bool turn;

public bool isDestroyed = false;

private bool isInvisible = false;

// Start is called before the first frame update

void Start()

{

spriteRenderer = GetComponent<SpriteRenderer>();

originalPos = originalPosObj.transform;

}

private void OnEnable()

{

turn = false;

}


// Update is called once per frame

void Update()

{

originalPos = originalPosObj.transform;

leftPos = originalPos.transform.position.x - 3f;

rightPos = originalPos.transform.position.x + 3f;


if (!isDestroyed)

{

if (!turn)

{

this.transform.Translate(Vector2.left * speed * Time.deltaTime);

if (this.transform.position.x <= leftPos)

{

spriteRenderer.flipX = true;

turn = true;

}

}

else if (turn)

{

this.transform.Translate(Vector2.right * speed * Time.deltaTime);

if (this.transform.position.x >= rightPos)

{

spriteRenderer.flipX = false;

turn = false;

}

}

}

else if(isDestroyed)

{

float rotationAmount = rotationSpeed * Time.deltaTime;

this.transform.Rotate(Vector3.back, rotationAmount);


Vector3 direction = new Vector3(10, -10, 0);

.

direction.Normalize();


Vector3 movement = direction * speed * Time.deltaTime;


this.transform.parent.Translate(movement, Space.Self);

}

if (isInvisible)

this.transform.parent.gameObject.SetActive(false);

}


private void OnTriggerEnter2D(Collider2D collision)

{

if (collision.tag == "Player")

{

if (StageManager.instance.isAlive)

{

if (!StageManager.instance.isInvincible && !StageManager.instance.isBoost && !StageManager.instance.isHitInvincivble)//&& !StageManager.instance.playerHit

{

StageManager.instance.playerHit = true;

StageManager.instance.mapScrollSpeed = 5.0f;

}

if (StageManager.instance.isBoost || StageManager.instance.isInvincible)

{

isDestroyed = true;

}

}

}

}

private void OnBecameInvisible()

{

if (isDestroyed)

isInvisible = true;

}

private void OnDisable()

{

isInvisible = false;

isDestroyed = false;

this.transform.rotation = Quaternion.Euler(Vector3.zero);

this.transform.parent.position = originalPos.position;

}

}



0cb3d92be4c631a960f1d1bc10f11a391998f779ec7af3c7af



7cef8375b4806ce864afd19528d52703f1a857e7f62e