Hi don't understand why I am getting these results for the vector 3 targets?

Hi guys
So I made a prefab called fire and in script 1 assigned a direction( targets = hit.collider.transform.position;). In script 2 i instantiated the object fire ( Instantiate (fire, transform.position, rotation)) and in script 3 was trying to guide it to target but the vector is been read but ignored in favor of a 0,0,0 return?? (transform.position = Vector3.Lerp(transform.position, myScript.targets, Time.deltaTime/10):wink:
No idea why the debug.log on the other scripts is returning the correct value at the same time as the 3rd script is giving a incorrect one.

II’m trying to do the particles this way as i can’t get onparticlecollision to work sigh.http://forum.unity3d.com/threads/onparticlecollision.302052/
Shameless thread plug:smile:

SCRIPT1

using UnityEngine;
using System.Collections;
public class magicuser : MonoBehaviour {
public int tier=1;
public magicspells myScript; //dragged and dropped in
public Vector3 targets;
public GameObject target;
string hitTag;
    int ray;
    int hit;
 
void update(){
Debug.Log (targets)//correct vector given


if (Input.GetMouseButtonDown (1)) {
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast (ray, out hit, 100)) {
                float distance = Vector3.Distance (hit.transform.position, transform.position);
                if (distance < 50) {
                        hitTag = hit.rigidbody.tag;
                        if (hitTag != ("null")) {
                                target = hit.transform.gameObject;
                         targets = hit.collider.transform.position;
                        //Debug.Log (hit.collider.transform.position);
                        //Debug.Log(hit.collider.name);
                        myScript.fireball ();Debug.Log (targets);//correct vector given;
SCRIPT2

using UnityEngine;
using System.Collections;
public class magicspells : MonoBehaviour {
public GameObject fire;
public Vector3 targets;
  int duration;
int damage;
int tier;
public magicuser myScript;

public   void fireball(){

        if (myScript.tier==1){
            Vector3 direction =myScript.targets - transform.position;
    Quaternion rotation = Quaternion.LookRotation (direction);
        Instantiate (fire, transform.position, rotation);//fire is the particle system GO
            damage=Random.Range (30,60); Debug.Log (targets)//correct vector given
            return;        }

SCRIPT3

using UnityEngine;
using System.Collections;
//this script is attached to the GO fire object.
public class movepart : MonoBehaviour {
    public magicuser myScript;//script dragged and dropped in
        
    // Update is called once per frame
    public void LateUpdate () {Debug.Log (myScript.targets+"ghfgfg"+myScript.targets);//returns a 0,0,0 vector incorrect
        transform.position = Vector3.Lerp(transform.position, myScript.targets, Time.deltaTime/10);
 
   }
    }

Do you only have one instance of Magicuser?

Is there any other code which could be zeroing the Targets Vector?

Nope the vector keeps its value only zeroes on script 3 don’t know if its becquse script 3 only becomes live once object is instantiated?.only 1 instance of magicuser.

Only way i can get it to work is this way

using UnityEngine;
using System.Collections;

public class movepart : MonoBehaviour {
//    public magicuser myScript;//this dioes not work with a dragged script reference
      Vector3 head;
     Transform transforms;
    magicuser playerScript;
    public void Start()
        {
        GameObject Mage = GameObject.Find ("mage");
        playerScript = Mage.GetComponent<magicuser> ();
        head = playerScript.targets;

        }
  

    public void LateUpdate () {
        transform.position = Vector3.Lerp(transform.position, head , Time.deltaTime);
        }
    }

Makes no sense a dragged reference to the same script returns a 0 vector 3 but a find object/getcomponent route returns the correct value. This despite the fact that magicspell and magicuser both use the drag reference to reference from one another and it works fine ???