Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kitty · Feb 16, 2010 at 10:14 PM · guitexture

Battery Collect Collision Problem

I have two sets of code. The PlayerCollisions script is suppose to allow for the door on a hut to be opened when four batteries are collected and shown in the gui texture shaped as a battery meter. The script is attached to the FPC with the BatteryCollect on the GUI texture.

The problem is that the gui does not show up and the batteries do not disappear and move the meter scale (clearly since it doesn't show up). If someone can look at the PlayerCollisions script and see if you can spot a problem with it, that would be awesome. I'm at a lost and it looks like it's correct and should work, but it does not.

PlayerCollision.js

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

var doorOpenTime : float = 3.0; var doorOpenSound : AudioClip; var doorShutSound : AudioClip; var batteryCollect : 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 && BatteryCollect.charge >= 4){
         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)

BatteryCollect.js

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kitty · Feb 22, 2010 at 04:29 PM

Haha wow! Thanks, Jaap.

The script I had works (except the door opening properly), but just made a simple, in my face error. I forgot to change the tags on the game objects to what they needed to be.

Yay! for blonde noob moments XD

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nicole · Aug 17, 2010 at 07:11 AM 0
Share

may i know where to put the batterycollect script? is it attached to the main camera?

avatar image
0

Answer by Jaap Kreijkamp · Feb 17, 2010 at 12:05 AM

The player doesn't get the OnTriggerEnter event but the battery does. Add a script to the battery with the OnTriggerEnter and let it send a message to the playercontroller, so you'd get something like this:

Script to add in battery:

function OnTriggerEnter(collisionInfo : Collider) {
    collisionInfo.gameObject.SendMessage("CollectBattery",
             gameObject, SendMessageOptions.DontRequireReceiver);
}

and replace OnTriggerEnter code in PlayerCollision.js with this:

function CollectBattery(battery : GameObject) {
    BatteryCollect.charge++;
    audio.PlayOneShot(batteryCollect);
    Destroy(battery);
}
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Gui Texture Swap? 1 Answer

Assign GUITexture in scene to variable via scripting? 1 Answer

Hide/Unhide GUITexture Help! 1 Answer

Draw GUI texture from it's center point. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges