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 /
avatar image
0
Question by Miller-M4 · Mar 27, 2018 at 06:08 AM · buttonaddforceplayer movement

Start Button

how can i make this script start after pressing button like tap to start if i put it on Update or Start when i press the button its so slow using UnityEngine;

 public class PlayerController : MonoBehaviour {
 
     public Rigidbody rb;
 
     public float forwardForce = 2000f;
     public float sidewaysForce = 500f;
 
     public void FixedUpdate ()
     {
             rb.AddForce (0, 0, forwardForce * Time.deltaTime);
 
         if (Input.GetKey ("d")) {
             rb.AddForce (sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
         }
 
         if (Input.GetKey ("a")) {
             rb.AddForce (-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
         }
 
         if (Input.GetMouseButton (0)) {
             if (Input.mousePosition.x > Screen.width / 2)
                 rb.AddForce (sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
             else
                 rb.AddForce (-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
         }
     }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mani3307 · Mar 27, 2018 at 07:14 AM

@Miller-M4 , What I understand from your question is you want to use a UI BUTTON to start the game,you can definetily do this refer this tutorial 1.)UI-button tutorial 2.)StartMenuTutorial Implement these tutorials in your required way and if you got any doubts ping me I will help for sure

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 Miller-M4 · Mar 27, 2018 at 07:33 PM 0
Share

i Fixed it thank you now the player have to press on screen to start but can you tell me does game get paused while showing ads cuz my restart button show ads while showing ads i can press on screen and player moving while showing ads

avatar image gonzalezc9999 Miller-M4 · Mar 27, 2018 at 07:44 PM 1
Share

while the adds are showing, you may have to put a script telling the game to be paused. For example, canceling all controls like putting your controls under a bool like this. I am not a great programmer but I will try to help your problem. using UnityEngine,Ui; using UnityEngine;

Pause $$anonymous$$enu : $$anonymous$$onoBehaviour { public bool isControllable = true; public bool AddPlaying = false;

void Update () { if(AddPlaying = true) { isControllable = false; } }

void Pause () { // create pause function // put up your add isControllable = false; AddPlaying = true; }

}

//in your controls function you could use a if statement to see if iscontrollable is true. If it is, you can move your character. something like this.

avatar image
0

Answer by Miller-M4 · Mar 27, 2018 at 08:44 PM

i tried a lot but nothing working this is my script now every thing is good expect when i press restart while ads showing i press on screen player start move and ads still showing and player crash and it repeating like this and can someone apply it to my script cuz i'm bad using UnityEngine; using UnityEngine.Advertisements; using UnityEngine.SceneManagement;

public class PlayerController : MonoBehaviour {

 public Rigidbody rb;

 public float forwardForce = 2000f;
 public float sidewaysForce = 500f;
 public bool Started = false;
 public GameObject StartText;

 void Start()
 {
     Started = false;
 }


 public void FixedUpdate ()
 {
     if (Input.GetMouseButtonDown (0)) {
         StartText.gameObject.SetActive (false);
         Started = true;
     }
     if (Started == true) {
         Time.timeScale = 1f;
         Time.fixedDeltaTime = 0.02f * Time.timeScale;
         rb.AddForce (0, 0, forwardForce * Time.deltaTime);

         if (Input.GetKey ("d"))
             rb.AddForce (sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
         {

             if (Input.GetKey ("a"))
                 rb.AddForce (-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);{
             }
         }
     }


     if (Input.GetMouseButton (0)) {
         if (Input.mousePosition.x > Screen.width / 2)
             rb.AddForce (sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
         else
             rb.AddForce (-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
     }
 }

 public void Restart()
 {
     SceneManager.LoadScene (SceneManager.GetActiveScene ().name);
     Time.timeScale = 1f;
     Time.fixedDeltaTime = 0.02f * Time.timeScale;
     Advertisement.Show ("video");
 }

}`

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

91 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

Related Questions

How to constantly add force to my player when a button is hold? 2 Answers

AddForce adding together on 2 button presses 1 Answer

how do I use a Raycast to apply force to the player on collision (in 2d)? 0 Answers

Increase Rigidbody2D Velocity based on player direction 1 Answer

Making player move based on mouse position universal for all screens 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