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)
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);
}
}