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 /
avatar image
0
Question by Omer.Hussain · Jan 23, 2014 at 10:38 AM · c#collisiononcollisionenterendless runnerendgame

how to stop my scene on collision..

Hi! i have script in which we create the endless track , 1st end 2nd starts, 2nd end then 1st start again in a linklist... and these tracks are moving toward my player which seems like it's running. what i want is on collision stop the track movement and player play an animation. in my below script "foreach(Transform road in roads) { road.Translate(0,0, -10f * Time.deltaTime); }" this one stop and start the movement .... kindly help me out please :( ... i am not good in c# ....

 using UnityEngine;
 using System.Collections.Generic;
 
 public class MoveRoad : MonoBehaviour {
     
     public Transform prefab;
     
     private LinkedList<Transform> roads = new LinkedList<Transform>();
     
     private float posY = 0.0f;
     private int numberOfRoads = 5;
 
     // Use this for initialization
     void Start () {
         
         // Init the scene with some road-pieces
         for(int i=0;i < numberOfRoads;i++) {
             Transform road = Instantiate(prefab) as Transform;
             road.Translate(0, posY, i * road.localScale.z);
             roads.AddLast(road);
         }
     }
     
     // Update is called once per frame
     void Update ( ) {
             
         Transform firstRoad = roads.First.Value;
         Transform lastRoad = roads.Last.Value;
         
         // Create a new road if the first one is not 
         // in sight anymore and destroy the first one
         if(firstRoad.localPosition.z < -40f) {
             roads.Remove(firstRoad);
             Destroy(firstRoad.gameObject);
             
             Transform newRoad = Instantiate(prefab, new Vector3(0, posY ,
                                                                 lastRoad.localPosition.z + lastRoad.localScale.z), 
                                             Quaternion.identity) as Transform;
             roads.AddLast(newRoad);
             
         }
 
         // Move the available roads along the z-axis
         foreach(Transform road in roads) {
 
             road.Translate(0,0, -10f * Time.deltaTime);
         }
     }
 
     
     //////////Collision Here////////////
 
     void OnCollisionEnter(Collision collision) {
 
         if (collision.gameObject.tag == "Hardle") {
             print("Collision-moveRoad");
             animation.CrossFade("jump_pose", 0.02F);
             //animation.Play("idle");
 
     //        Time.timeScale= 0.0f;
 
 
         }
     }
 }

 
Comment
Add comment · Show 3
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 Graham-Dunnett ♦♦ · Jan 23, 2014 at 10:39 AM 0
Share

Have a boolean variable called moving. Only do the foreach when moving is true. Set moving false in your collision code.

avatar image Omer.Hussain · Jan 23, 2014 at 01:03 PM 0
Share

Thanx @Graham you are right ..

avatar image Chevyalf · Mar 12, 2016 at 03:03 PM 0
Share

Work for me

1 Reply

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

Answer by FrankHHansen · Jan 23, 2014 at 12:00 PM

I would sugget making a Bool that you could call moveRoads and set that to true, Upon collision, set it to false.

in the update where the roads are moved, check if moveRoads is true and move the roads if it is.

 // Move the available roads along the z-axis
 foreach(Transform road in roads) 
 {
     //Only move the roads if the moveRoads is true.
     if(moveRoads)
     {
         road.Translate(0,0, -10f * Time.deltaTime);
     }
 }
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 Omer.Hussain · Jan 23, 2014 at 01:02 PM 0
Share

it works :)

avatar image Omer.Hussain · Jan 23, 2014 at 01:12 PM 0
Share

@frank Ok ... now on collision my road stop moving but when i collide with the object (Hardle) my player push the hurdle and through it away .. .... what i should do next ... on my object rigid body is applied, box collider is applied, in rigid body either gravity toogle on or off same stuff....... i applied rigid body on the player as well , his mass 1 and Hardle mass 100 but again player through it away ... :/ ...

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

21 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

Related Questions

Simple collision? 2 Answers

OnCollisionEnter2D not being called on entering new tile once already called. 1 Answer

Distribute terrain in zones 3 Answers

Checking for collision with 2D objects/sprites 3 Answers

Collision issue with SetParent (C#) 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