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 /
  • Help Room /
avatar image
0
Question by molooco · Jan 12, 2017 at 03:36 AM · c#mouse

Hi im having the error The name `currentFramePosition' does not exist in the current context i can't find a solution can someone help me?

Basicly the title says everything this issue is repeted in lines: 32,70/47,24/53,36/55,36/85,39

File where the issue is linked to using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class MouseController : MonoBehaviour {
 
     public GameObject CircularCursor;
 
     Vector3 lastFramePosition;
     Vector3 dragStartPosition;
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
 
         Vector3 currentFramePosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
         currentFramePosition.z = 0;
 
         UpdateCursor();
         UpdateDragging();
         UpdateCameraMovement();
             
         lastFramePosition = Camera.main.ScreenToWorldPoint( Input.mousePosition );
         lastFramePosition.z = 0;
     }
     void UpdateCursor() {
         // Update the circle cursor position
         Tile tileUnderMouse = WorldController.Instance.GetTileAtWorldCoord(currentFramePosition);
         if(tileUnderMouse != null) {
             CircularCursor.SetActive(true);
             Vector3 cursorPosition = new Vector3(tileUnderMouse.X, tileUnderMouse.Y, 0);
             CircularCursor.transform.position = cursorPosition;
         }
         else {
             // Mouse is outside of the valid tile space, so hide the cursor.
             CircularCursor.SetActive(false);
         }
     }
 
     void UpdateDragging() {
         // Start Drag
         if( Input.GetMouseButtonDown(0) ) {
             dragStartPosition = currentFramePosition;
         }
 
         // End Drag
         if( Input.GetMouseButtonUp(0) ) {
             int start_x = Mathf.FloorToInt( dragStartPosition.x );
             int end_x =   Mathf.FloorToInt( currentFramePosition.x );
             int start_y = Mathf.FloorToInt( dragStartPosition.y );
             int end_y =   Mathf.FloorToInt( currentFramePosition.y );
 
             // We may be dragging in the "wrong" direction, so flip things if needed.
             if(end_x < start_x) {
                 int tmp = end_x;
                 end_x = start_x;
                 start_x = tmp;
             }
             if(end_y < start_y) {
                 int tmp = end_y;
                 end_y = start_y;
                 start_y = tmp;
             }
 
             // Loop through all the tiles
             for (int x = start_x; x <= end_x; x++) {
                 for (int y = start_y; y <= end_y; y++) {
                     Tile t = WorldController.Instance.world.GetTileAt(x, y);
                     if(t != null) {
                         t.Type = Tile.TileType.Grass;
                     }
                 }
             }
         }
     }
 
     void UpdateCameraMovement() {
         // Handle screen panning
         if( Input.GetMouseButton(1) || Input.GetMouseButton(2) ) {    // Right or Middle Mouse Button
 
             Vector3 diff = lastFramePosition - currentFramePosition;
             Camera.main.transform.Translate( diff );
 
         }
     }
 }

Thanks in advanced

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 Bunny83 · Jan 12, 2017 at 05:23 AM 0
Share

$$anonymous$$oved to the help room as this question is a trivial problem which is based on lacking of understanding basic program$$anonymous$$g principles.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jan 12, 2017 at 05:26 AM

You declared your currentFramePosition variable as a local variable inside your Update method:

 void Update () {
     Vector3 currentFramePosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);

That means the variable only exists during the execution of the Update method and is not available anywhere else.

You most likely want to declare the variable inside your class as member variable:

 Vector3 currentFramePosition;
 
 void Update () {
     currentFramePosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
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

270 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 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 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

Mouse-Keyboard Not Working - New User 1 Answer

Rotating object on z axis only when following mouse movements. 0 Answers

Can't Get Prefab Clone To Follow Mouse 2 Answers

Draggable Door Problems 0 Answers

How to tilt a sprite based on pointer position? 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