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.

68 lines
2.7 KiB

6 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Player : MonoBehaviour
  5. {
  6. public List<GameObject> dummies;
  7. public Vegetable heldVeggie;
  8. public GameObject playerModel;
  9. protected Map map;
  10. private Animator playerAnim;
  11. private List<Animator> dummieAnims = new List<Animator>();
  12. public float scale = 0.1f;
  13. public void Start()
  14. {
  15. playerAnim = playerModel.GetComponent<Animator>();
  16. }
  17. protected virtual void Update()
  18. {
  19. UpdateDummies();
  20. }
  21. public void CreateDummies(Map map)
  22. {
  23. this.map = map;
  24. dummies.Add(Instantiate(playerModel, new Vector3(transform.position.x - map.TileSize * map.MapDimensions.x, transform.position.y, transform.position.z), transform.rotation, transform).gameObject);
  25. dummies.Add(Instantiate(playerModel, new Vector3(transform.position.x + map.TileSize * map.MapDimensions.x, transform.position.y, transform.position.z), transform.rotation, transform).gameObject);
  26. dummies.Add(Instantiate(playerModel, new Vector3(transform.position.x, transform.position.y, transform.position.z - map.TileSize * map.MapDimensions.y), transform.rotation, transform).gameObject);
  27. dummies.Add(Instantiate(playerModel, new Vector3(transform.position.x, transform.position.y, transform.position.z + map.TileSize * map.MapDimensions.y), transform.rotation, transform).gameObject);
  28. foreach (GameObject dummie in dummies)
  29. {
  30. Debug.Log(dummie.name);
  31. dummieAnims.Add(dummie.GetComponentInChildren<Animator>());
  32. foreach (Collider col in dummie.GetComponentsInChildren<Collider>())
  33. {
  34. col.enabled = false;
  35. }
  36. }
  37. }
  38. public void UpdateDummies()
  39. {
  40. dummies[0].transform.position = transform.position - (Vector3.right * (map.TileSize * map.MapDimensions.x * scale));
  41. dummies[1].transform.position = transform.position + (Vector3.right * (map.TileSize * map.MapDimensions.x * scale));
  42. dummies[2].transform.position = transform.position - (Vector3.forward * (map.TileSize * map.MapDimensions.y * scale));
  43. dummies[3].transform.position = transform.position + (Vector3.forward * (map.TileSize * map.MapDimensions.y * scale));
  44. int count = 0;
  45. foreach (GameObject dummie in dummies)
  46. {
  47. dummie.transform.rotation = playerModel.transform.rotation;
  48. Debug.Log(dummieAnims[count]);
  49. dummieAnims[count].SetFloat("WalkSpeed", playerAnim.GetFloat("WalkSpeed"));
  50. if (playerAnim.GetBool("PickUp"))
  51. dummieAnims[count].SetTrigger("PickUp");
  52. }
  53. }
  54. }