Commit 67992c6c authored by Cody A Burchett's avatar Cody A Burchett

flame crab

parent b1edcb29
fileFormatVersion: 2
guid: 3449ac6e2a03fd54fa5d10fa4b3518ac
timeCreated: 1475798950
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class FlameCrab : MonoBehaviour {
public float moveDelay = 5f;
public float speed = 5f;
public float health = 10f;
float nextMove = 0f;
Vector3 targetLocation = -Vector3.up;
Rigidbody2D body;
// Use this for initialization
void Start () {
body = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
if (nextMove < Time.time)
{
if (targetLocation != -Vector3.up)
{
if ((transform.position - targetLocation).sqrMagnitude > .15f)
{
Move();
}
else
{
nextMove = Time.time + moveDelay;
targetLocation = -Vector3.up;
}
}
else
{
//find new target location to right or left of enemy
int spacesToMove = Random.Range(-5, 6);
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.right, spacesToMove, 1);
if (hit.collider)
{
targetLocation = hit.point;
}
else
{
targetLocation = transform.position + (transform.right * spacesToMove);
}
}
}
}
void Move()
{
Vector3 dir = targetLocation - transform.position;
body.transform.Translate(dir.normalized * speed * Time.deltaTime);
}
}
fileFormatVersion: 2
guid: ad04fbd2b7592974baa491ea766a0337
timeCreated: 1475799560
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment