Yo, i meet with another brick wall while trying to create my own scripting…
well… i have a variable named “TrackPoint” that is a transform gameobject… and that object is only attached to this var at runtime… when i certain condition is reached… (only when colides with a object tagged “aimable”)
as you see bellow
var TrackPoint = gameObject;
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "aimable")
TrackPoint = other.gameObject;
okay, now, the trackpoint var has the gameobject assigned to it… now what i want to do is sent a projectile in the direction of the object , the trackpoint…
how do i do that?
i tried to use getcomponent… like this :
var storecordinates = trackpoint.GetComponent.(Vector3);
and then , instantiate a projectile and transform.position (storedcordinates)
First, you should try to reserve capitalization for methods and class names, and camelCase your vars and properties in Unity.
Second, Vector3 is not a component, but there is a variable of the Transform component (position) that returns the Vector3 position of the object, as you can see here: Unity - Scripting API: Transform. You should probably read the docs a little more to get a handle on the different runtime classes of different types of objects in Unity.
Transform is a special component that does not require GetComponent to access, you can use the .transform shortcut. So, in your case, you would want to say something like:
var trackPointPos = trackPoint.transform.position;
Then you can instantiate your projectile or whatever, have it rotate towards the trackPoint by either slerping the rotation or using the LookAt() function, and move it forward.
i cant use this trackPointPos you mentioned because that is not a static var… and if i try to make it static it gives me an error…
q:why do i need it to be static?
a: so i can mentionate this var in a script attached to the projectile that im planing to shoot in those cordinates… you see… the projectile is a homing misile… a prefab and the only way for me to make it move is to put a script on it… because we all know that is just impossible to move something remotely… i mean… i cant move this prefab into the trackPointPos direction from here… i gotta move it from a script IN the prefab
and i swear, i been reading those docs like crazy but those examples never ever make sense to me… i mean… they never show something im actualy using
like,… like this page you sent me, actualy i been reading this page before too… but look at the example:
" // Moves all transform children 10 units upwards!
for (var child : Transform in transform) {
child.position += Vector3.up * 10.0;
} "
You don’t need a static var… if you want a script on the instantiated projectile to have access to the transform of trackPoint, then you can just pass it to whatever script is on the projectile once you instantiate in this script (assuming it is set).
For instance, assuming you had a prefab for your projectile (we’ll call it “projectilePrefab”) and it has a script called “MyHomingMissileScript” on it. In MyHomingMissileScript, you have:
public var trackPointTransform : Transform;
In THIS script, you would pass the transform of the trackPoint object you have in a var here, to the MyHomingMissileScript script, after you instantiated a projectile:
hi um legend 411 i read one of you’r former ???about the fact that youc could not swing you’r sword and run at the same time properly and i goy a ??? of my own and that is that ok you seem varry smart ,and this is of subject,if you wold like to help out n00b like me with a skript, a dude, texture, animation, or/and whatever iwold reeeeeeeaaaaaaly like that thank you.?.?.?.!?.
i found another way to do it with transform.look at then adding force forward… but… your way totaly makes sense now! this solution seems so easy …thanks anyway man… im gonna save these scripts because im definetly gonna need it again!..