123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SphereController : MonoBehaviour
- {
- private Vector3 RespawnPoint;
- private Quaternion RespawnOrientation;
- bool isReplace;
- private Rigidbody _rigidbody;
- BoxCollider box;
- public float _force = 1;
- private Vector3 direction;
- Vector3 _tempPos=Vector3.zero;
- bool isThrow = false;
- List<Vector3> posList=new List<Vector3>();
-
- // Start is called before the first frame update
- void Start()
- {
- _rigidbody = GetComponent<Rigidbody>();
- box = GetComponent<BoxCollider>();
- RespawnPoint = this.transform.position;
- RespawnOrientation = this.transform.rotation;
- }
- private void Update()
- {
- }
- public void Throwing()
- {
- if (box.enabled==true)
- {
- box.enabled = false;
- }
- _tempPos = this.transform.position;
- posList.Add(_tempPos);
- }
- public void ThrowEnd()
- {
- isThrow = true;
- }
- void LateUpdate()
- {
- if (isThrow)
- {
- AddForce();
- isThrow = false;
- }
- }
- public void AddForce()
- {
- if (posList.Count > 9)
- {
- direction = (posList[posList.Count - 1] - posList[posList.Count - 5]).normalized;
- Debug.Log(direction + "——————" + posList.Count);
- _rigidbody.AddForce(direction * _force, ForceMode.Force);
- }
-
- posList.Clear();
- }
- private void replace()
- {
- if (_rigidbody != null)
- {
- _rigidbody.velocity = Vector3.zero;
- _rigidbody.angularVelocity = Vector3.zero;
- }
- this.transform.SetPositionAndRotation(RespawnPoint, RespawnOrientation);
- if (box.enabled==false)
- {
- box.enabled = true;
- }
- isReplace = false;
- Debug.Log("LGS: RePlace");
- }
- public void OnCollisionEnter(Collision collision)
- {
- //if (collision.gameObject.tag == "collision")
- //{
- // Debug.Log(collision.gameObject.name);
- // direction = (this.transform.position - collision.transform.position).normalized;
- // _rigidbody.AddForce(direction * _force, ForceMode.Force);
- //}
- //else
- if(collision.gameObject.tag=="floor" && isReplace==false)
- {
- Invoke("replace", 2f);
- isReplace = true;
- }
-
- }
- public void OnCollisionStay(Collision collision)
- {
-
- }
- public void OnCollisionExit(Collision collision)
- {
-
- }
- }
|