Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TrackingProjectile : BaseProjectile {
- GameObject m_target;
- private Rigidbody rb;
- public float Push = 3;
- GameObject m_launcher;
- int m_damage;
- public GameObject Explosion;
- Vector3 m_LastKnownPostion;
- private void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- if (m_target)
- {
- m_LastKnownPostion = m_target.transform.position;
- }
- else
- {
- if(transform.position == m_LastKnownPostion)
- {
- //Object is created where the bomb is on impact, this creates the explosion before despawning
- GameObject BoomHolder = Instantiate(Explosion, gameObject.transform.position, gameObject.transform.rotation) as GameObject;
- //Destroy the Bomb
- Destroy(gameObject);
- //Destory the BoomHolder after 5 Seconds (Make this slightly longer than your clip)
- Destroy(BoomHolder, 5.0f);
- }
- }
- transform.position = Vector3.MoveTowards(transform.position, m_LastKnownPostion, Speed * Time.deltaTime);
- transform.LookAt(m_target.transform, m_target.transform.up);
- rb.AddRelativeForce(0, 0, Push);
- }
- public override void FireProjectile(GameObject launcher, GameObject target, int damage, float attackSpeed)
- {
- if (target)
- {
- m_target = target;
- m_LastKnownPostion = target.transform.position;
- m_launcher = launcher;
- m_damage = damage;
- }
- }
- //Same deal as in the base projectile we will add this code in the Message Handler portion of the tutorial
- public void OnCollisionEnter(Collision other)
- {/*
- if (other.gameObject == m_target)
- {
- DamageData dmgData = new DamageData();
- dmgData.damage = m_damage;
- MessageHandler msgHandler = m_target.GetComponent<MessageHandler>();
- if (msgHandler)
- {
- msgHandler.GiveMessage(MessageType.DAMAGED, m_launcher, dmgData);
- }
- }
- //Dont destroy when you come in contact with bullets otherwise do destroy
- if (other.gameObject.GetComponent<BaseProjectile>() == null)
- Destroy(gameObject);
- */}
- }
Advertisement
Add Comment
Please, Sign In to add comment