- Home /
Shadow Projector Component not pointed down
Hi all,
I am trying to get drop shadows on my prefab characters. I've already imported Blob Shadow et al from Standard Assets.
I have 10 characters running around at once, so I attached a Projector component to the character's prefab, then gave it the shadow material. Unfortunately, it's pointed straight out, instead of down!
When I go into an update routine and try this:
var proj : Projector = GetComponent (Projector);
proj.transform.rotation.eulerAngles.x = 90;
It rotates the parent object! (which is not a Projector, BTW. =D )
I tested to see if there was a transform on the projector using this line of code:
if (proj.transform == null) print("null");
But it never printed, making me think it does have a transform.
So... if you know of a different way to get a standard blob on multiple characters, or know what I'm doing wrong here, please let me know!
Thank you!
Answer by Waz · Aug 23, 2011 at 01:18 AM
The Projector is a component on a GameObject. The GameObject has a Transform. Components do not themselves have a Transform. Look in the Inspector and this will become clear.
If you only want to rotate the Projector and not the whole GameObject it is on, then put it on a child of that game object and rotate the transform of that child object.
To make a child object, Create Empty and drag it to the parent object.
I see that now; the Standard Asset was just a prefab. O$$anonymous$$. New knowledge, thanks!
Still having an issue, though... :(
I created a "DropShadow" prefab thus:
Project -> Create -> Prefab
Game Object -> Create Empty
Select new object -> Add Projector component
Change material to shadow
Drag object to prefab
Delete game object
Test prefab by dropping into scene. Works! O$$anonymous$$.
Added to game object thus:
In script (not sure how to mark code blocks in replies): var shadowObj : GameObject;
Dragged "DropShadow" prefab to its place in the Inspector
In the Update function for the object: shadowObj.transform.position = transform.position; shadowObj.transform.position.y += 2;
Aaaaand... nothing! :( Did I overlook something fundamental?
The only useful thing to do with a Prefab dragged to a script variable is to Instantiate it in that script.
So either do that or drag a real scene object to that slot, not the prefab from which it was made.
Yes, that was the issue. Learning is FUNdamental, eh? Ehhh??
But seriously, thank you!