x


Battery Collect Player Collisions Script Problems!

It throws no errors up for me but still when i start the game the battery 2d gui dissapears and when a walk into the battery nothing happens here is my player collisions script and my battery collect script.

private var doorIsOpen : boolean = false; 
private var doorTimer : float = 0.0; 
private var currentDoor : GameObject; 

var batteryCollect : AudioClip;
var doorOpenTime : float = 3.0; 
var doorOpenSound : AudioClip; 
var doorShutSound : AudioClip; 

function Update () { 
   if(doorIsOpen){ 
      doorTimer += Time.deltaTime; 
   if(doorTimer > 3){ 
      shutDoor();  
      doorTimer = 0.0;    
   }    
var hit : RaycastHit;  
   if(Physics.Raycast (transform.position,      
      transform.forward, hit, 5)) {    
   if(hit.collider.gameObject.tag=="outpostDoor" && doorIsOpen == 
   false){    
      currentDoor = hit.collider.gameObject;        
      Door(doorOpenSound, true, "dooropen", currentDoor);      
         GameObject.Find("Battery GUI").GetComponent(GUITexture).enabled=false;    
}    
}  
} 
} 
function OnControllerColliderHit(hit: ControllerColliderHit){  
if(hit.gameObject.tag == "outpostDoor" && doorIsOpen == false){    
currentDoor = hit.gameObject;    
Door(doorOpenSound, true, "dooropen", currentDoor); 
} 
} 

function OpenDoor(){ 
audio.PlayOneShot(doorOpenSound);  
doorOpen = true;    
      var myOutpost : GameObject = GameObject.Find("outpost");  
         myOutpost.animation.Play("dooropen");}function shutDoor(){    
         audio.PlayOneShot(doorShutSound);    doorIsOpen = false;  
      var myOutpost : GameObject = GameObject.Find("outpost");    
         myOutpost.animation.Play("doorshut"); 
} 

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);   
}

}

@script RequireComponent(AudioSource)

and here is my battery script

static var charge : int = 0;

var charge1tex : Texture2D;
var charge2tex : Texture2D;
var charge3tex : Texture2D;
var charge4tex : Texture2D;
var charge0tex : Texture2D;

function Start(){   
    guiTexture.enabled = false; 
    charge = 0;
}

function Update () {
    if(charge == 1){
        guiTexture.texture = charge1tex;
        guiTexture.enabled = true;
    }
    else if(charge == 2){
        guiTexture.texture = charge2tex;
    }
    else if(charge == 3){
        guiTexture.texture = charge3tex;
    }
    else if(charge == 4){
        guiTexture.texture = charge4tex;
    }
    else{
        guiTexture.texture = charge0tex;
        }
}
more ▼

asked Mar 23 '10 at 08:34 PM

canihazaqueztion gravatar image

canihazaqueztion
1 1 1 1

All of your code segments need to be surrounded by

 [...] 
tags to make it easier to read.
Mar 24 '10 at 03:01 AM qJake
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

First, make sure that you assigned the right tag to the battery objects and that they are all tagged as "battery".
I had the same problem working this example and what i found isnt so much an error on your part as a glitch in unity, so this is what solved it for me. Select one of your battery objects in the scene, in the Inspector you should have a Capsule Collider component, if you followed the example correctly. In this component is the "Is Trigger" checkbox, chances are this box is already checked, but are the words "Is Trigger" in bold?????? if not, simply decheck the box next to Is Trigger and recheck it again and "In Trigger" should now be in bold. Hopefully this helps, thats what did it for me, i think its a glitch in unity.

more ▼

answered Nov 10 '10 at 10:13 PM

RPH gravatar image

RPH
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2485
x803

asked: Mar 23 '10 at 08:34 PM

Seen: 1109 times

Last Updated: Jun 08 '10 at 09:55 PM