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.

76 lines
2.7 KiB

5 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. public Animator playerAnim;
  11. public List<Animator> dummieAnims = new List<Animator>();
  12. public float scale = 0.1f;
  13. protected virtual 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. if (dummies.Count < 4)
  41. return;
  42. dummies[0].transform.position = transform.position - (Vector3.right * (map.TileSize * map.MapDimensions.x * scale));
  43. dummies[1].transform.position = transform.position + (Vector3.right * (map.TileSize * map.MapDimensions.x * scale));
  44. dummies[2].transform.position = transform.position - (Vector3.forward * (map.TileSize * map.MapDimensions.y * scale));
  45. dummies[3].transform.position = transform.position + (Vector3.forward * (map.TileSize * map.MapDimensions.y * scale));
  46. int count = 0;
  47. foreach (GameObject dummie in dummies)
  48. {
  49. dummie.transform.rotation = playerModel.transform.rotation;
  50. dummieAnims[count].SetFloat("WalkSpeed", playerAnim.GetFloat("WalkSpeed"));
  51. if (playerAnim.GetBool("PickUp"))
  52. dummieAnims[count].SetTrigger("PickUp");
  53. }
  54. }
  55. public virtual void SetName(string Name)
  56. {
  57. }
  58. }