Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void CastLightning()
- {
- GameObject ligtning = Instantiate(lightningPrefab, Vector3.zero, Quaternion.identity);
- LightningBoltScript lightningScript = ligtning.GetComponent<LightningBoltScript>();
- lightningScript.StartPosition = shootPoint.position;
- if (hit.collider != null)
- {
- lightningScript.EndPosition = hit.point;
- if (hit.collider.gameObject.CompareTag("Player"))
- {
- hit.collider.gameObject.GetComponent<PlayerHealth>().TakeDamage(85); //TEMP
- }
- }
- else
- {
- lightningScript.EndPosition = transform.forward * 100;
- }
- lineR.enabled = false;
- lerpPercent = 0;
- }
- public void InitiateAiming() //для типов врагов, которые целятся, вызывается в начале анимации
- {
- lineR.enabled = true;
- timer = Time.time + aimTime; //заново целимся
- }
- private void Aim()
- {
- lineR.SetPosition(0, shootPoint.position);
- if (Time.time < timer)
- {
- targetRotation = Quaternion.LookRotation(playerTr.position - thisTr.position);
- lerpPercent += 0.1f * Time.fixedDeltaTime;
- thisTr.rotation = Quaternion.Lerp(thisTr.rotation, targetRotation, lerpPercent);
- Vector3 normal = GetPointOfContactNormal(thisTr.position + Vector3.up, new Vector3(thisTr.forward.x, (playerTr.position - thisTr.position).normalized.y, thisTr.forward.z));
- lineR.SetPosition(1, hit.point);
- }
- else if(lineR.enabled)
- {
- Vector3 normal = GetPointOfContactNormal(thisTr.position + Vector3.up, new Vector3(thisTr.forward.x, (playerTr.position - thisTr.position).normalized.y, thisTr.forward.z));
- if(normal != Vector3.zero)
- lineR.SetPosition(1, hit.point);
- else
- lineR.SetPosition(1, thisTr.forward * 100);
- }
- }
- private Vector3 GetPointOfContactNormal(Vector3 pos, Vector3 dir)
- {
- Ray ray = new Ray(pos, dir);
- if (Physics.Raycast(ray.origin, ray.direction, out hit, 300, obstaclesAndPlayerLayerMask))
- {
- return hit.normal;
- }
- return Vector3.zero;
- }
- public void TurnOffLinecast()
- {
- lineR.enabled = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement