This commit is contained in:
2025-05-13 05:05:49 +03:00
parent a68d9ccb42
commit 235216efe2
606 changed files with 684027 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
using UnityEngine;
using System.Collections;
public class CrossbowArrow : MonoBehaviour {
public Vector3 StartPoint;
public Vector3 EndPoint;
public Vector3 CurrentPosition;
public Vector3 NextPosition;
public float Speed;
public GameObject physicsHits;
private float distance = 0.0f;
private RaycastHit hit;
private Vector3 forward;
// Use this for initialization
void Start () {
forward = (EndPoint - StartPoint).normalized;
}
// Update is called once per frame
void Update () {
CurrentPosition = StartPoint + (EndPoint - StartPoint).normalized * distance;
distance += Time.deltaTime * Speed;
NextPosition = StartPoint + (EndPoint - StartPoint).normalized * distance;
if (distance >= 50) {
Destroy (this);
} else {
RaycastHit hit;
if(Physics.Raycast(new Ray(CurrentPosition, forward), out hit)){
//Debug.Log("Pointing on: " + hit.collider.gameObject.name);
if(hit.distance <= (NextPosition - CurrentPosition).magnitude){
NextPosition = CurrentPosition + transform.forward * hit.distance;
Destroy(gameObject);
var mat = hit.collider.sharedMaterial;
string hitName = "HitDefault";
if(mat != null && mat.name == "Glass"){
hitName = "HitGlass";
}
GameObject hitObjSrc = physicsHits.transform.FindChild(hitName).gameObject;
GameObject hitObj = (GameObject)Instantiate(hitObjSrc);
hitObj.transform.localPosition = hit.point;
hitObj.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
hitObj.SetActive(true);
//hit.normal
}
}else{
//Debug.Log("Pointing on: Nothing");
}
}
transform.position = NextPosition;
}
void OnDrawGizmos(){
Gizmos.DrawLine (CurrentPosition, CurrentPosition + forward * 10);
}
}