• 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
Question by fournicknet · Jan 07, 2013 at 05:31 PM · c#cameramousemove

C# move main camra via mouse position on boarders around screen script for RTS Game

So I have been working on this for a few hours now. I know I'm new but i'm trying to learn what I'm doing wrong I have seen alot of different scripts on the forums but they don't seem to do what I want. The idea is that as the gamer will move the mouse to the edge of any four sides of the screen and the if statment will then move the camera when it detects the movement. Each update it is suppose to scroll faster. When the user moves the coursor off the edge of the screen it should stop the movement of the camera but doesn't. I have tried to implement an else if and else statement but it seems to ignore those. Code shown below. Thanks!

 using UnityEngine;
 using System.Collections;
 
 public class cameraLook : MonoBehaviour {
     
     public float speed = 10.0f;  //velocity at which the screen should move, won't work right now becuase movement.x,y is set to 0 at end of the code
     public Vector3 movement = Vector3.zero;
     public float maxScreenWidth = Screen.width - 20;  //code that identifes max screen width for conditional statement
     public float maxScreenHeight = Screen.height - 20;  // code that identifies max screen height   "     "      "
     public float numberOfPixlesToMove = 1;
     
     // Use this for initialization
     void Start () {
     
         Debug.Log ("Can this run!!!");
         
     }
     
     // Update is called once per frame
     void LateUpdate () {
     
         if (Input.mousePosition.x <= 20) //moves screen to the left
         {
             movement.x = movement.x-numberOfPixlesToMove;
         }
         
         if (Input.mousePosition.x >= maxScreenWidth) // moves screen to the right
         {
             movement.x = movement.x+numberOfPixlesToMove;
         }
 
         if (Input.mousePosition.y <= 20)// moves screen up
         {
             movement.y = movement.y-numberOfPixlesToMove;
         }
         
         if (Input.mousePosition.y >= maxScreenHeight)// moves screen down
         {
             movement.y = movement.y+numberOfPixlesToMove;
         }
         
         //else if(movement.x = 0, movement.y = 0);
         
         /*
         else if (Input.mousePosition.x >= 20 && Input.mousePosition.x <= maxScreenWidth || Input.mousePosition.y >= 20 && Input.mousePosition.y <= maxScreenWidth)
         {
             movement.x = 0;
             movement.y = 0;
         }    
         */
         
         /*
         if (Input.mousePosition.y >= 20 || Input.mousePosition.y <= maxScreenWidth)
         {
             movement.y = 0;
         }    
         */
         
         
         /*
         else
         {
             movement.x = 0;
             movement.y = 0;
         }
         */
         
         
         
         transform.Translate (movement * speed * Time.deltaTime, Space.Self);
         
         
         
     //    movement.x = 0; // if this line and the line below are commented out it will have some velocity with movement
     //    movement.y = 0;
     //    return;
     }
 }
Comment
Flickayy

People who like this

1 Show 0
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera move when reach edge of screen 3 Answers

Camera follow mouse around the map 2 Answers

C# Decrease Mouse Sensitivity Camera Move 0 Answers

No Glitch Please ... 1 Answer

How do I make my character lean to the sides? 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