Tuesday, March 29, 2011

Alien Artifacts Full Screen Inventory GUI Part 2

OK I created the first of my 4 "Alien Artifacts" that "Farmer Bob" will need to collect throughout the game. I knew this part of my game was destined to be a real pain in the ass but I had no idea the pain I'm getting into with his. First off I thought; "Oh sure this should just be a simple matter of creating my Alien Artifact, plopping on the sound for it to emit, then plop on the "PickUp" java script, lob all that into a prefab and then make a new UFO Animation event that will Instantiate my new prefab close to where my UFO crashes." and is it that simple? Frak No! First off the way I thought to code it was wrong so I popped on over to Unity Answers to get hopefully a lead in the right direction. Some of kind folk there helped me out by providing this script to add into my UFOanimationEvents.js:
var explosion : GameObject;
var wreck : GameObject;
//var artifactTarget : Transform;
var alienArtifact : GameObject;
function ExplodeUFO()
{
        Instantiate(explosion, transform.position, transform.rotation);
}
function KillSelf () {
        yield WaitForSeconds(3);
        var wreckClone = Instantiate(wreck, transform.position, transform.rotation);
        Destroy(gameObject);
}
function dropArtifact () {
    var artifactPosition = Vector3(276.7286, 5.241356, 963.852);
    var artifactRotation = Vector3(270, 0,0);

    var Artifact01 = Instantiate(alienArtifact, artifactPosition.position, artifactRotation.rotation);
    print("Artifact created");
}
Highlighted bits are what's been added to my existing UFOanimationEvents.js It's supposed to instantiate my "Alien Artifact" at a precise location so that way when "Farmer Bob" goes to investigate the UFO crash he will find the first Artifact.
But can I get a break and something would actually work for a change? Hell no! For some reason this is not working. So I thought I would try it another way. I moved my "Animation Event" back a few frames so that way the "Alien Artifact" would get sort of dropped mid-air a short distance from the UFO when it crashes. Sounds good right? Wrong!. It would just fall through the ground. So I had to give it a ridged body and turn off the boxcollider trigger. so now it does NOT fall through the ground anymore, but now my FPS player can't pick it up!! Grrrrrr... Frak, Frak and Double Frak!!

No comments: