Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by carter-carl30 · Mar 28, 2012 at 08:48 PM · destroykeyboarddisableshoot

Help with game, stopping player cheating (script help)

I am using 2 scripts (kindly helped by "immesivegamer") (see scripts below), in my breakout style game.

The problem I have is that with the current setup, the player can still press "space" and fire another ball whilst one is already in game. So the player can fire one ball hit a few blocks then if the ball is going to hit the floor they can press "space" and fire another, saving losing a life! (good for testing the game though! hehe)

Is there a way to disable the pressing of the spacebar until the ball in play is destroyed (by hitting the floor when they miss)? or something to add to the script/scripts to achieve this?

any help/suggestions appriciated

---------- Script on my shoot object: ----------

var thePrefab : GameObject;

 var MaxObjectCount = 0;
 
 function Update () {
 
 if(Input.GetButtonDown("Jump")){
 
 var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
 
    instance.name = "Bullet";
 
      MaxObjectCount += 1;
 
 if(MaxObjectCount == 2){
 
    Destroy(GameObject.Find("Bullet"));
 
    MaxObjectCount -=1;
 
 }
 
 }
 
 }


---------- Script on my floor: ---------- var shootObject : GameObject;

function OnCollisionEnter ( collision : Collision) {

if (collision.collider.name == "Bullet"){

 var shootScript : testshootscript = shootObject.GetComponent(testshootscript);



 Destroy (GameObject.Find("Bullet"));


 shootScript.MaxObjectCount -= 1;

   lives.LIVES -= 1;


//adding in to destroy Bullet_super if hits floor (without removing a life)

if (collision.collider.name == "Bullet_super"){

   Destroy (GameObject.Find("Bullet_super"));

  

}

}

}


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

1 Reply

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

Answer by rutter · Mar 28, 2012 at 10:05 PM

Looks like you're already tracking the number of bullets. Why not just check if that's greater than zero in the same spot you're checking for user input?

Comment
Add comment · Show 3 · 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 carter-carl30 · Mar 29, 2012 at 05:46 PM 0
Share

hi rutter, I don't understand, could you please explain what you mean? (i'm newbie at scripting trying to wrap my head around it all)

avatar image rutter · Mar 30, 2012 at 04:11 AM 0
Share

Here:

 if(Input.GetButtonDown("Jump")){

You could change this to:

 if(Input.GetButtonDown("Jump") && $$anonymous$$axObjectCount < 1){
avatar image carter-carl30 · Mar 30, 2012 at 06:53 PM 0
Share

thankyou very much rutter, that works perfectly :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do you find out what connectedBody, a Rigidbody belongs to? 0 Answers

Shoot. Just Shoot 5 Answers

Help with script (limiting gameobject but when destroyed allowing again) 1 Answer

Disable Mouse click 1 Answer

Trouble With Disableing a Function 1 Answer


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