You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
2.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public List<GameObject> dummies;
public Vegetable heldVeggie;
public GameObject playerModel;
protected Map map;
public Animator playerAnim;
public List<Animator> dummieAnims = new List<Animator>();
public float scale = 0.1f;
public void Start()
{
playerAnim = playerModel.GetComponent<Animator>();
}
protected virtual void Update()
{
UpdateDummies();
}
public void CreateDummies(Map map)
{
this.map = map;
dummies.Add(Instantiate(playerModel, new Vector3(transform.position.x - map.TileSize * map.MapDimensions.x, transform.position.y, transform.position.z), transform.rotation, transform).gameObject);
dummies.Add(Instantiate(playerModel, new Vector3(transform.position.x + map.TileSize * map.MapDimensions.x, transform.position.y, transform.position.z), transform.rotation, transform).gameObject);
dummies.Add(Instantiate(playerModel, new Vector3(transform.position.x, transform.position.y, transform.position.z - map.TileSize * map.MapDimensions.y), transform.rotation, transform).gameObject);
dummies.Add(Instantiate(playerModel, new Vector3(transform.position.x, transform.position.y, transform.position.z + map.TileSize * map.MapDimensions.y), transform.rotation, transform).gameObject);
foreach (GameObject dummie in dummies)
{
Debug.Log(dummie.name);
dummieAnims.Add(dummie.GetComponentInChildren<Animator>());
foreach (Collider col in dummie.GetComponentsInChildren<Collider>())
{
col.enabled = false;
}
}
}
public void UpdateDummies()
{
if (dummies.Count < 4)
return;
dummies[0].transform.position = transform.position - (Vector3.right * (map.TileSize * map.MapDimensions.x * scale));
dummies[1].transform.position = transform.position + (Vector3.right * (map.TileSize * map.MapDimensions.x * scale));
dummies[2].transform.position = transform.position - (Vector3.forward * (map.TileSize * map.MapDimensions.y * scale));
dummies[3].transform.position = transform.position + (Vector3.forward * (map.TileSize * map.MapDimensions.y * scale));
int count = 0;
foreach (GameObject dummie in dummies)
{
dummie.transform.rotation = playerModel.transform.rotation;
dummieAnims[count].SetFloat("WalkSpeed", playerAnim.GetFloat("WalkSpeed"));
if (playerAnim.GetBool("PickUp"))
dummieAnims[count].SetTrigger("PickUp");
}
}
}