var theClonedExplosion : GameObject;
theClonedExplosion = Instantiate(explosion,transform.position, transform.rotation);
var tmpScript:Scriptname = theClonedExplosion.GetComponent("ScriptName");
//Do the editing here and you get a prefab with the edited attribute
What error? Does the SabotRounds exist? You have the GetComponent wrong, between <> you have to put a class name.
For a string you have to use GetCompoenent("Scriptname") as Scriptname
Now I have a gameObject that is named trajectory holder which holds a float value of the trajectory height. When I use the function to get the distance it sends the trajectory height to this trajectory holderobject, because I can’t change the prefab before it is fired.
So when the prefab is fired I need to get this value that is stored in the holder. So that would go into the above example correct??
I have this script attaching to the projectile when the projectile is instantiated-
/
/
/
public Vector3 startPos;
public Vector3 endPos;
public float trajectoryHeight;
public GameObject Target;
void Start()
{
}
void Update ()
{
startPos = Target.transform.position;
endPos = Target.transform.position;
// calculate current time within our lerping time range
float cTime = Time.deltaTime * 0.2f;
// calculate straight-line lerp position:
Vector3 currentPos = Vector3.Lerp(startPos, endPos, cTime);
// add a value to Y, using Sine to give a curved trajectory in the Y direction
currentPos.y += trajectoryHeight * Mathf.Sin(Mathf.Clamp01(cTime) * Mathf.PI);
// finally assign the computed position to our gameObject:
transform.position = currentPos;
}
public void Range(float value)
{
trajectoryHeight = value;
}
}
/
/
/
Also when the script attaches to the projectile the Target, which is the prefab projectile doesn’t get put in the Target and I get a instance of the object not reference error.
I know I need to store the value of the trajectory height in a different script because when I get the distance the prefab doesn’t exist yet, but how do I get the value to the prefab the instant it is instantiated???
I used all the refence examples and none of them work…
I try and attach the script to the prefab but it attaches the blank script with 0 values and throws this error-
/
/
Failed to call function RangeHolder of class TrajectoryHolder
Calling function RangeHolder with no parameters but the function requires 1.
UnityEngine.Component:SendMessage(String, SendMessageOptions)
Sabot:Update() (at Assets/Scripts/Player_Scripts/Sabot.cs:21)
/
/
I’m not going to guess what the code looks like now but these are 3 you might want to work with
get the gameObject then gameObject.sendmessage(“function”, arg ); which makes it easy to send messages, Try to keep these out of Update() and other coroutines. And keep plugging at it you’re close.
well guess you shouldn’t be doing this in Update() before it exists hence the errors. Sorry for not being helpful maybe use a Invoke when it does exist.
*// finally assign the computed position to our gameObject:*