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 mineus64 · Aug 15, 2013 at 02:44 PM · vehicle

Vehicle Script Modifications

How do I modify this script so that a projectile is emitted from a gameObject when the player presses enter, but only when the player is in the vehicle?

     using UnityEngine;
     using System.Collections;
     public class Vehicle : MonoBehaviour {
         public Camera VehicleCamera;
         public GameObject Player;
         private bool InVehicle;
         private bool VehicleControl;
           public float Speed = 80.0F;
          public float RotationSpeed = 100.0F;
         public Transform _Player;
         private float Distance;
         public Transform _Vehicle;
         private Vector3 VehiclePos;
         void Start()
         {
             VehicleCamera.gameObject.SetActive(false);
         }
         void Update()
         {
             Distance = Vector3.Distance(_Player.position, transform.position);
             if(Distance < 6)
             {
             if(Input.GetKeyDown(KeyCode.Tab))
             {
                 InVehicle = true;
             }
             }
             else if(InVehicle)
             {
             if(Input.GetKeyDown(KeyCode.Tab))
             {
                 InVehicle = false;
                 VehiclePos = new Vector3(_Vehicle.transform.position.x + 5, _Vehicle.transform.position.y, _Vehicle.transform.position.z);
                 _Player.transform.position = VehiclePos;
             }
             }
             if(InVehicle)
             {
                 VehicleCamera.gameObject.SetActive(true);
                 Player.gameObject.SetActive(false);
                 VehicleControl = true;
             }
             else
             {
                 VehicleCamera.gameObject.SetActive(false);
                 Player.gameObject.SetActive(true);
                 VehicleControl = false;
             }
             if(VehicleControl)
             {
             float tr = Input.GetAxis("Vertical") * Speed;
             float rot = Input.GetAxis("Horizontal") * RotationSpeed;
             tr *= Time.deltaTime;
             rot *= Time.deltaTime;
             transform.Translate(0, 0, tr);
             transform.Rotate(0, rot, 0);
             }
         }
         void OnGUI()
         {    if(InVehicle == false)
             {
             if(Distance < 6)
             {
                 GUILayout.Label("Press TAB");
             }
             }
         }
        
     }
Comment
Add comment · Show 2
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 MadJohny · Aug 15, 2013 at 03:24 PM 1
Share

I guess you would just put the the part to create the projectile inside of the statement on line 37 (if (inVehicle) {}) I guess you would put inside there, if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Enter)) {and you write the code to send the projectile here} also, I don't know what the $$anonymous$$eyCode for Enter is, search it for yourself you will probably find it

avatar image mineus64 · Aug 15, 2013 at 04:01 PM 0
Share

Return....

0 Replies

· Add your reply
  • Sort: 

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

16 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

Related Questions

Multiple Cars not working 1 Answer

I need help instantiateing a bullet 0 Answers

Problem with vehicle script 1 Answer

Saving a value if it is larger than the current value... 3 Answers

Vehicle Script Debugging 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