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 /
  • Help Room /
avatar image
0
Question by eregoczy · Mar 30, 2017 at 03:44 PM · spawningpausemouseclickgetmousebuttondown

How to make spawned in game objects pause with mouse click.

Hi, Ive got three columns spawning in and I want one column to pause for 5 seconds when i use GetMouseButtonDown. Any help would be amazing! Thanks.

These are the three columns of squares spawning in: alt text

this is my main script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Main : MonoBehaviour {

 public static float Range;

 

 public GameObject[] squaresDownArray;
 public GameObject[] squaresUpArray;
 public GameObject square;


 int index;

 public Color[] colourArray;


 public Vector2 leftSpawnPosition;
 public Vector2 midSpawnPosition;
 public Vector2 rightSpawnPosition;

 public float spawnTimer;
 private float spawnCounter;

 private int squareIndexCounter;



 // Use this for initialization
 void Start () {



 


     
     //squaresDownArray = GameObject.FindGameObjectsWithTag ("SquareDown");
     //squaresUpArray = GameObject.FindGameObjectsWithTag ("SquareUp");


     InvokeRepeating ("TimerTick", 0, 1);

 }
 
 // Update is called once per frame
 void Update () {
     spawnCounter += Time.deltaTime;



     
 }


         public void TimerTick(){
     
     if(spawnCounter >= spawnTimer){
     GameObject lSquare = Instantiate (square, leftSpawnPosition, Quaternion.identity);
     lSquare.tag = "SquareDown";
         //lSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
         lSquare.GetComponent<MeshRenderer>().materials[0].color = colourArray[Random.Range(0,colourArray.Length)];

         squareIndexCounter++;
         if (squareIndexCounter >= colourArray.Length) {
             squareIndexCounter = 0;
         }

     GameObject mSquare = Instantiate (square, midSpawnPosition, Quaternion.identity);
     mSquare.tag = "SquareUp";
         //mSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
         mSquare.GetComponent<MeshRenderer>().materials[0].color = colourArray[Random.Range(0,colourArray.Length)];




     squareIndexCounter++;
         if (squareIndexCounter >= colourArray.Length) {
             squareIndexCounter = 0;
         }

     GameObject rSquare = Instantiate (square, rightSpawnPosition, Quaternion.identity);
     rSquare.tag = "SquareDown";
         //rSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
         rSquare.GetComponent<MeshRenderer>().materials[0].color = colourArray[Random.Range(0,colourArray.Length)];



             //[squareIndexCounter];



         squareIndexCounter++;
         if (squareIndexCounter >= colourArray.Length) {
             squareIndexCounter = 0;
         }
         spawnCounter -= spawnTimer;
     } 

     foreach (GameObject square in GameObject.FindGameObjectsWithTag("SquareUp")) {
         square.GetComponent<SquareScript> ().Move ("up");




     }
     foreach (GameObject square in GameObject.FindGameObjectsWithTag("SquareDown")) {
         square.GetComponent<SquareScript> ().Move ("down");


     }



         


 }

}

this is my script for my squares:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class SquareScript : MonoBehaviour {

 public float moveSpeed;
 private float moveTimeCounter;
 public float moveDistance;
 private Vector3 endPos;

 private float averageDTime;
 private int averageDTCounter;
 private bool moving;

 Main Main;

 // Use this for initialization
 void Start () {
     Main = Main.GetComponent<Main> () as Main;

 }
 
 // Update is called once per frame
 void Update () {

     if (Input.GetMouseButton (0)) {
         moving = false;
     }



     if (transform.position.y > 8 || transform.position.y < -8) {
         Destroy (gameObject);
     }

     if (moving) {
         
         if (moveTimeCounter <= 1) {
             moveTimeCounter += Time.deltaTime * moveSpeed;
             averageDTime += Time.deltaTime;
             averageDTCounter++;
         } else {
             moveTimeCounter = 0;
             moving = false;
             print (averageDTime / averageDTCounter);
             averageDTCounter = 0;
             averageDTime = 0;
         }
         transform.position = Vector3.Lerp (transform.position, endPos, moveTimeCounter);
     }
 }

 public void Move(string moveDirection){
     moving = true;
     if (moveDirection == "up") {
          endPos = new Vector3 (transform.position.x, transform.position.y + moveDistance, 0);
     }
     if (moveDirection == "down") {
         endPos = new Vector3 (transform.position.x, transform.position.y - moveDistance, 0);
     }

 }
     

}

and this is the mouse down script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class ClickScript : MonoBehaviour {

 public float speed = 0.1F;

 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {

     if (Input.GetMouseButtonDown (0))
         Debug.Log ("Pressed left click.");

     if (Input.GetMouseButtonDown (1))
         Debug.Log ("Pressed right click.");

     if (Input.GetMouseButtonDown (2))
         Debug.Log ("Pressed middle click.");



     if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Moved) {
         // Get movement of the finger since last frame
         Vector2 touchDeltaPosition = Input.GetTouch (0).deltaPosition;

         // Move object across XY plane
         transform.Translate (-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
         Debug.Log ("swipe.");
 
     }


 }

 }

screen-shot-2017-03-30-at-164004.png (30.0 kB)
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

Answer by Whayman · Apr 03, 2017 at 03:58 PM

somebody reply pls

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

98 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

Related Questions

Inconsistent GetMouseButtonDown Behaviour 1 Answer

columns wont pause on mouseclick 0 Answers

Endless Runner with new Biome each time 0 Answers

How to program a pause/unpause button in C#. 2 Answers

How to pause an animation 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