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 tayyab43 · Oct 22, 2013 at 07:04 PM · compile errors

How do I move my gun to "position B"?

i made a script for aiming down the sight but it won't move the object, how do i do it? I keep getting this error? here's my script:

 using UnityEngine;
 using System.Collections;
 
 public class AimingDownSight : MonoBehaviour {
     private Vector3 newPosition;
     void Awake()
     {
         newPosition = transform.position;    
     }
     void Update () 
     {
         positionChanging();
     }
 
     void positionChanging()
     {
         Vector3 positionA = new Vector3 (0.3946627f, -0.1788931f, 0.7112392f);
         Vector3 positionB = new Vector3(0.009421766f, -0.1324487f, 0.5510964f);
         
         
         if (Input.GetMouseButtonDown(1))
         {
             newPosition = positionB;
             transform.position(new Vector3(0.009421766f, -0.1324487f, 0.5510964f));
         }
     
         else
         {
             newPosition = positionA;
             transform.position(new Vector3(0.3946627f, -0.1788931f, 0.7112392f));
         }
         transform.position = Vector3.Lerp (transform.position, newPosition, Time.deltaTime);
     } 
 }
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 robertbu · Oct 22, 2013 at 10:25 PM

When posting code with an error, please copy the entire error message from the console and post it with your question. Your issues appear to be lines 24 and 30. 'transform.position' is not a method, so you cannot deal with it this way. In addition, if I'm guessing correctly about what you want this code to do, you don't want either line in your script. Also Input.GetMouseButtonDown() only returns true for a single frame. I think you want Input.GetMouseButton(). Here is your code with these two fixes, plus I added a 'speed' variable. If you don't want eased motion at the ends, you can Vector3.MoveTowards() instead of Lerp().

 using UnityEngine;
 using System.Collections;
  
 public class AimingDownSight : MonoBehaviour {
     public float speed = 5.0f;
     private Vector3 newPosition;
 
     void Awake()
     {
        newPosition = transform.position; 
     }
     void Update () 
     {
        positionChanging();
     }
  
     void positionChanging()
     {
        Vector3 positionA = new Vector3 (0.3946627f, -0.1788931f, 0.7112392f);
        Vector3 positionB = new Vector3(0.009421766f, -0.1324487f, 0.5510964f);
  
  
        if (Input.GetMouseButton(1))
        {
          newPosition = positionB;
          //transform.position(new Vector3(0.009421766f, -0.1324487f, 0.5510964f));
        }
  
        else
        {
          newPosition = positionA;
          //transform.position(new Vector3(0.3946627f, -0.1788931f, 0.7112392f));
        }
        transform.position = Vector3.Lerp (transform.position, newPosition, Time.deltaTime * speed);
     } 
 }
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

14 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

Related Questions

Shader error in ... : Syntax error at line 30 1 Answer

unity editor.screen view compile error 0 Answers

Transform bug only happening in Compiled build 0 Answers

Standard Assets 0 Answers

help!! Internal compiler error. See the console log for more information. output was: 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