Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerSpells : MonoBehaviour {
  6.  
  7.     bool moveTowards = false;
  8.     GameObject FIREBALL;
  9.     Vector3 point;
  10.  
  11.     [Header("Spell Effects Objects")]
  12.     public GameObject PS_HEALINGPAD;
  13.     public GameObject PS_FIREBALL;
  14.  
  15.     public enum spellType
  16.     {
  17.         Heal,
  18.         Single,
  19.         Area,
  20.         Link
  21.     }
  22.  
  23.     // Use this for initialization
  24.     void Start () {
  25.        
  26.     }
  27.    
  28.     // Update is called once per frame
  29.     void Update () {
  30.         if (Input.GetKeyDown(KeyCode.E))
  31.         {
  32.  
  33.             Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2.0f, Screen.height / 2.0f, 0));
  34.             RaycastHit hit;
  35.             if (Physics.Raycast(ray, out hit, 200))
  36.             {
  37.                 point = hit.point;
  38.                 StartCoroutine("fish");
  39.             }
  40.         }
  41.  
  42.  
  43.  
  44.     }
  45.  
  46.     IEnumerator fish()
  47.     {
  48.         GameObject player = GameObject.Find("FPSController");
  49.         GameObject FIREBALL = Instantiate(PS_FIREBALL, player.transform.position, Quaternion.identity);
  50.         //FIREBALL.transform.SetParent(player.transform);
  51.         yield return new WaitForSeconds(2.5f);
  52.         moveTowards = true;
  53.         moveBall(FIREBALL);
  54.         yield return null;
  55.     }
  56.  
  57.  
  58.     void moveBall(GameObject FIREBALL)
  59.     {
  60.         if (moveTowards == true)
  61.         {
  62.             if(FIREBALL.transform.position != point)
  63.             {
  64.                 Debug.Log("I hit: " + point);
  65.                 Debug.Log(moveTowards);
  66.                 FIREBALL.transform.position = Vector3.MoveTowards(FIREBALL.transform.position, point, Time.deltaTime * 5);
  67.                 Debug.Log(FIREBALL);
  68.             }
  69.         }
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement