Project
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Enemie : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float speed;
|
||||
private Vector2 velocity = new Vector2();
|
||||
[SerializeField] private float rayOffset = 0.6f;
|
||||
private SpriteRenderer spriteRenderer;
|
||||
private Animator animator;
|
||||
private float timeHit = 0;
|
||||
[SerializeField] private float dieDelay;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
velocity.x = -speed;
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
transform.Translate(velocity * Time.deltaTime);
|
||||
|
||||
if (timeHit != 0)
|
||||
{
|
||||
if (Time.time - timeHit > dieDelay)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D col)
|
||||
{
|
||||
if(col != null)
|
||||
{
|
||||
if (col.tag.Equals("Player"))
|
||||
{
|
||||
if(col.GetComponent<Player>().velocity.y < 0)
|
||||
{
|
||||
col.GetComponent<Player>().BounceUp();
|
||||
Hit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.x *= -1;
|
||||
spriteRenderer.flipX = !spriteRenderer.flipX;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.x *= -1;
|
||||
spriteRenderer.flipX = !spriteRenderer.flipX;
|
||||
}
|
||||
}
|
||||
|
||||
public void Hit()
|
||||
{
|
||||
Destroy(GetComponent<Collider2D>());
|
||||
velocity.x = 0;
|
||||
animator.SetInteger("value", 1);
|
||||
timeHit = Time.time;
|
||||
}
|
||||
|
||||
public void FlipX()
|
||||
{
|
||||
OnTriggerEnter2D(null);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
OnTriggerEnter2D(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60442abe595b11042b0bbca0d4268e75
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Mushroom : MonoBehaviour
|
||||
{
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
if(col.contacts[0].normal.x < -0.8f || col.contacts[0].normal.x > 0.8f)
|
||||
{
|
||||
Player player;
|
||||
|
||||
if ((player = col.gameObject.GetComponent<Player>()) == true)
|
||||
{
|
||||
player.TakeDamage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 751521379053e754590c0ca299b9a7ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Saw : MonoBehaviour
|
||||
{
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
Player player;
|
||||
|
||||
if ((player = col.gameObject.GetComponent<Player>()) == true)
|
||||
{
|
||||
player.TakeDamage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4f3fe87e57e37649a4606964b1d6347
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Spikes : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool moving;
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D col)
|
||||
{
|
||||
Player player;
|
||||
|
||||
if ((player = col.gameObject.GetComponent<Player>()) == true)
|
||||
{
|
||||
player.TakeDamage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff10e84cfca03a94296fa9ab10ce3429
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user