Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Problem with Chapter 7 of Development Essentials

Discussion in 'Assets and Asset Store' started by DarkKnight, May 16, 2011.

  1. DarkKnight

    DarkKnight

    Joined:
    Apr 2, 2011
    Posts:
    22
    First off I just want to say , this is by far the best book for learning unity it helped me understand a great deal and even thou I did run into some problems time to time I was able to work them out.

    everything was going fine until I added the script for setting fire.
    Whats happening is the GUI texthint is up at the start and through out the game play once I reach the door the text flickers and seems to over ride the door texthint but doesn't over ride the platform texthint.
    once inside the outpost the matchbox nolonger shows up on the screen , and when I exit the fire is already lit.




    function OnControllerColliderHit (hit : ControllerColliderHit) {
    if (hit . collider . gameObject == GameObject . Find ("campfire")) {
    }
    if (haveMatches) {
    haveMatches = false;
    lightFire();
    } else {
    TextHints . textOn=true;
    TextHints . message = "I'll need some matches to light this camp fire..";
    }
    var crosshairObj : GameObject = GameObject . Find ("Crosshair");
    var crosshair : GUITexture = crosshairObj .
    GetComponent ( GUITexture );
    if ( hit.collider == GameObject . Find ("mat") . collider) {
    CoconutThrow . canThrow=true;
    crosshair . enabled = true;
    TextHints.textOn = true ;
    TextHints . message = " Knock down all 3 at once to win a battery!";
    GameObject . Find ("TextHint GUI") . transform.position.y = 0.2;
    }
    else{
    CoconutThrow . canThrow=false;
    crosshair . enabled = false ;
    GameObject . Find ("TextHint GUI") . transform . position .y = 0.5;
    }
    }


    function Door ( aClip : AudioClip, openCheck : boolean, animName : String, thisDoor : GameObject){
    audio . PlayOneShot (aClip);
    doorIsOpen = openCheck;

    thisDoor . transform . parent . animation . Play (animName);
    }
    function OnTriggerEnter ( collisionInfo : Collider ) {

    if ( collisionInfo . gameObject . tag == "battery") {
    BatteryCollect . charge++;
    audio . PlayOneShot ( batteryCollect);
    Destroy ( collisionInfo . gameObject);
    }
    if (collisionInfo.gameObject.name == "matchbox") {
    Destroy ( collisionInfo.gameObject);
    haveMatches=true;
    audio.PlayOneShot (batteryCollect);
    var matchGUIobj : GameObject = Instantiate (matchGUI, Vector3 (0.15,0.1,0) ,transform.rotation);
    matchGUIobj.name = "matchGUI";
    }
    }
    function lightFire(){
    var campfire : GameObject = GameObject . Find("campfire");
    var campSound : AudioSource = campfire . GetComponent (AudioSource);
    campSound . Play();

    var flames : GameObject = GameObject . Find ("FireSystem");
    var flameEmitter : ParticleEmitter = flames . GetComponent ( ParticleEmitter);
    flameEmitter . emit = true;

    var smoke : GameObject = GameObject . Find ("SmokeSystem");
    var smokeEmitter : ParticleEmitter = smoke . GetComponent (ParticleEmitter);
    smokeEmitter . emit = true;
    Destroy(GameObject . Find ("matchGUI"));
    }

    @script RequireComponent (AudioSource)
     

    Attached Files:

    Last edited: May 16, 2011