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 xToxicInferno · Aug 22, 2010 at 01:15 AM · crash

Script crashes unity

When ever i have this script active and try to run the game, it crashes Unity. I've got no idea why so can someone please explain:

var walkSpeed : float = 1.0; var runSpeed : float = 2.0; var gridSize : int = 10;

function Start () { var myTransform = transform; var startPosition : Vector3; var endPosition : Vector3; var t : float; var tx : float; var moveSpeed = walkSpeed; while(true) { if(Input.GetButtonDown("Fire1")){ var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit;

         if (Physics.Raycast(ray,hit)) {
         startPosition = myTransform.position;
         endx = hit.transform.position.x/2;
         endz = hit.transform.position.z/2;
         endPosition = Vector3(endx,0,endz);

             while (t < 1.0) {
                 moveSpeed = Input.GetButton("Run")? runSpeed : walkSpeed;
                 t += Time.deltaTime * (moveSpeed/gridSize);
                 myTransform.position = Vector3.Lerp(startPosition, endPosition, t);
                 yield;
             }
         }
         tx = t - 1.0;   // Used to prevent slight visual hiccups on "grid lines" due to Time.deltaTime variance 
     }
 }

}

Comment
Add comment · Show 1
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 Eagle32 · Aug 22, 2010 at 02:57 AM 0
Share

I find with bugs that cause editor crashes the best thing to do first is to do a standalone build then run that and perform whatever action was crashing your game in the standalone build. A lot of the time the game won't crash in the standalone build. You can then check the log file and get a more useful error message that will help you narrow down the problem.

3 Replies

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

Answer by Eric5h5 · Aug 22, 2010 at 02:56 AM

You have an infinite loop. It's checking for the fire button being down an infinite number of times in one frame. I assume you want a yield in there.

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
avatar image
-1

Answer by HolBol · Oct 04, 2010 at 06:33 PM

change start to Update()

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
avatar image
0

Answer by Ben 14 · Oct 04, 2010 at 06:33 PM

Eric5h5 has it, but I don't think you can yield inside Start(). Try either firing another function and do the yield in there, or even more simply move the content of your while(true) to the Update() function which will be called on each frame.

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 Adam Rademacher · Nov 21, 2010 at 12:06 AM 0
Share

Start can yield. In C# you'd have to declare it as an IEnumerator but javascript does it automatically. The issue above is the while(true) that never has a break.

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

A node in a childnode? 1 Answer

Why does Unity 3.0 fail to start on OS X (Mac) 3 Answers

Unity3d Crash error (Mono.dll) with NetworkView 0 Answers

Unity + dk2 compilation problem 1 Answer

Profiler crashes unity 0 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