Commit de9143a9 authored by James D Fonda's avatar James D Fonda

Adding basic slime script

parent 44408661
using UnityEngine;
using System.Collections;
public class basic_slime_script : MonoBehaviour
{
private Vector3 player_position;
private Vector3 slime_position;
private GameObject player;
private float x_diff;
private float y_diff;
// Use this for initialization
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
}
// Update is called once per frame
void Update()
{
//get position of player character
player_position = player.transform.position;
//get position of slime
slime_position = transform.position;
//compare to position of slime (self)
x_diff = player_position.x - slime_position.x;
y_diff = player_position.y - slime_position.y;
if (Mathf.Abs(x_diff) >= Mathf.Abs(y_diff))
{
//if move is valid, then move
if (x_diff < 0)
{
if (World.get((int)(slime_position.x - 1 + 0.5), (int)(slime_position.y + 0.5)).walkable == true)
transform.position += Vector3.left;
}
if (x_diff > 0)
{
if (World.get((int)(slime_position.x + 1 + 0.5), (int)(slime_position.y + 0.5)).walkable == true)
transform.position += Vector3.right;
}
}
else
{
//if move is valid, then move
if (y_diff < 0)
{
if(World.get((int)(slime_position.x + 0.5), (int)(slime_position.y - 1 + 0.5)).walkable == true)
transform.position += Vector3.down;
}
if (y_diff > 0)
{
if (World.get((int)(slime_position.x + 0.5), (int)(slime_position.y + 1 + 0.5)).walkable == true)
transform.position += Vector3.up;
}
}
}
}
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