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 /
This question was closed May 15, 2019 at 11:40 AM by M_Shazaib.
avatar image
0
Question by M_Shazaib · May 15, 2019 at 10:13 AM · scripting problemscript.scripting beginner

what to change in the script that it calls start from a external button other then when collider is detected

I have this script that counts the balloons destroyed along with a timer it starts when a collider in my case a paper plane collides with it I want to change it starts when I press a button from my other UI

 using UnityEngine;
 using System.Collections;
 
 namespace DaydreamElements.SwipeMenu {
 
   [RequireComponent(typeof(AudioSource))]
   public class Sign : MonoBehaviour {
     private TextMesh textMesh;
     private float timerEnd;
     private int prevTime;
     private AudioSource audioSource;
 
     private static bool started = false;
     private static int score = 0;
 
     public GameObject signText;
 
     public static void IncScore() {
       if (started) {
         ++score;
       }
     }
 
     void Start() {
       audioSource = GetComponent<AudioSource>();
       textMesh = signText.GetComponent<TextMesh>();
       Debug.Assert(textMesh != null);
     }
 
     void Update() {
       if (started) {
         int newTime = (int)(timerEnd - Time.realtimeSinceStartup) + 1;
         if (newTime <= 0) {
           started = false;
           textMesh.text = "Game Over!\nShoot again to restart\nYour score: " + score + "\n";
         } else if (newTime != prevTime) {
           prevTime = newTime;
           textMesh.text  = "00:" + newTime.ToString("00") + "\nYour score: " + score + "\n";
           if (newTime == 5) {
             audioSource.Play();
           }
         }
       }
     }
 
     void OnCollisionEnter(Collision collision) {
       RigidPaperAirplane rigidPencil = collision.gameObject.GetComponent<RigidPaperAirplane>();
       if (rigidPencil == null) {
         return;
       }
       if (!started) {
         started = true;
         timerEnd = Time.realtimeSinceStartup + 60.0f;
         prevTime = 0;
         score = 0;
       }
     }
   }
 }


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

  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · May 15, 2019 at 10:42 AM

Hello.

Then just move everything inside OnCollisionEnter() into a new void method called for example StartTime()

And in Update just add this:

 if (Input.GetKeyDown(KeyCode.Space))
 {
 StartTime();
 }

Add any other condition if you need.

Bye!

Comment
Add comment · Show 2 · 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 M_Shazaib · May 15, 2019 at 11:06 AM 0
Share
 it says collision does not exist in current context
         void Startcount()
         {
           //it says that collision dosent exist
          RigidPaperAirplane rigidPencil = **collision**.GetComponent<RigidPaperAirplane>();
             if (rigidPencil == null)
             {
                 return;
             }
             if (!started)
             {
                 started = true;
                 timerEnd = Time.realtimeSinceStartup + 60.0f;
                 prevTime = 0;
                 score = 0;
             }

avatar image tormentoarmagedoom M_Shazaib · May 15, 2019 at 11:33 AM 0
Share

Oh come on... move everything but adapt to new situation.... you are not iside ontrigger methood, ther is no colliders...

I think You should watch some tutorials and learn more before continue..

Follow this Question

Answers Answers and Comments

193 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to allow the key to only open 1 door rather than all of them? 0 Answers

(PLEASE HELP) hi guys! i have a problem with my Score text 1 Answer

Wait for animation to finish 2 Answers

How do I make my projectile deal damage to a target it hit. 1 Answer

How do I make do I make a variable go back to its original value for a spell system 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