| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Foot : MonoBehaviour
- {
- public Rigidbody rb;
- public bool haveGravity = true;
- public bool TrigGround
- {
- get
- {
- return trigGroundList.Count > 0;
- }
- }
- public List<GameObject> trigGroundList;
- private void Update()
- {
- rb = GetComponentInParent<Rigidbody>();
- if (trigGroundList.Count == 0)
- {
- if (!haveGravity)
- {
- rb.useGravity = true;
- haveGravity = true;
- rb.GetComponent<MoveCharacter>().velocityAddition = 0;
- }
- }
- else
- {
- if (haveGravity)
- {
- if (rb.velocity.y <= 0)
- {
- foreach (GameObject i in trigGroundList)
- {
- if (i.layer == 13)
- {
- rb.useGravity = false;
- rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
- haveGravity = false;
- rb.transform.position = new Vector3
- (rb.transform.position.x, i.transform.position.y, rb.transform.position.z);
- break;
- }
- }
- }
- }
- else
- {
- Platform platform = trigGroundList[0].GetComponent<Platform>();
- if (platform != null && platform.rb != null)
- {
- rb.GetComponent<MoveCharacter>().velocityAddition = platform.rb.velocity.x;
- }
- }
- }
- }
- private void FixedUpdate()
- {
- for (int i = 0; i < trigGroundList.Count; i++)
- {
- if (trigGroundList[i] == null)
- {
- trigGroundList.RemoveAt(i);
- i--;
- }
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Plane"))
- {
- //if (notOnGiant)
- //{
- // Platform platform = other.gameObject.GetComponent<Platform>();
- // if (platform)
- // {
- // return;
- // }
- //}
- if (!trigGroundList.Exists(t => t == other.gameObject))
- {
- trigGroundList.Add(other.gameObject);
- }
-
- }
- }
- private void OnTriggerExit(Collider other)
- {
- for (int i = 0; i < trigGroundList.Count; i++)
- {
- if (trigGroundList[i] == other.gameObject)
- {
- trigGroundList.RemoveAt(i);
- i--;
- }
- }
- }
- }
|