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 CybernetHacker14 · Jul 25, 2018 at 02:49 PM · scripting problembug-perhaps

Need help with a script execution fault

I have a script execution problem. Basically in the following attached code, the script works perfectly at the starting first usage iteration. But then when I repeat the process the second time, the value of _isSelecting variable is not updated, as I see it in the Inspector Window. I need to see if the fault is in my scripting, or is there a problem in the compiler.

 using UnityEngine.EventSystems;
 using UnityEngine;
 using System.Collections.Generic;
 
 public class EngineClickHandlerModule : MonoBehaviour {
 
     // Access different modules of Engine
     EngineSelectionModule _sm;
     EngineUnitFormationModule _ufm;
     EngineBuildingPlacementModule _blpm;
 
     [SerializeField]
     List<GameObject> selectedObjects = new List<GameObject>();
 
     [SerializeField]
     bool _isSelecting = false;
 
     Vector3 _mousePosition1;
     Vector3 _mousePosition2;
 
     // Use this for initialization
     private void Awake()
     {
         _sm = GameObject.Find("SelectionManager").GetComponent<EngineSelectionModule>();
         _ufm = GameObject.Find("UnitFormationManager").GetComponent<EngineUnitFormationModule>();
     }
 
     // Update is called once per frame
     void Update () {
 
         if (EventSystem.current.IsPointerOverGameObject())
         {
             _isSelecting = false;
             return;
         }
 
 
         if (Input.GetMouseButton(0))
         {
             if (_isSelecting == false)
             {
                 Debug.Log("Clicking");
                 foreach(var selectableObject in FindObjectsOfType<UnitSystems>())
                 {
                     if (!IsWithinSelectionBounds(selectableObject.gameObject))
                     {
                         selectableObject.transform.root.Find("SelectionCircleHalo").gameObject.SetActive(false);
                     }                    
                 }
                 selectedObjects.Clear();
                 _sm.ResetUnitSelection();
                 _mousePosition1 = Input.mousePosition;
                 _isSelecting = true;
             }            
         }
         else
         {
             _isSelecting = false;
         }
 
         if (_isSelecting)
         {
             foreach(var selectableObject in FindObjectsOfType<UnitSystems>())
             {
                 if (IsWithinSelectionBounds(selectableObject.transform.root.gameObject))
                 {
                     if (!selectedObjects.Contains(selectableObject.transform.root.gameObject))
                     {
                         selectableObject.transform.root.Find("SelectionCircleHalo").gameObject.SetActive(true);
                         selectedObjects.Add(selectableObject.transform.root.gameObject);
                     }                    
                 }
             }
         }
 
         if (Input.GetMouseButtonUp(0))
         {
             _mousePosition2 = Input.mousePosition;
             if(_mousePosition1 == _mousePosition2)
             {
                 ClickOperations(0);
             }
             else
             {
                 _sm.SetMultipleSelectedUnitsList(selectedObjects);
             }
         }
 
 
 
         if (Input.GetMouseButtonDown(1))
         {
             _isSelecting = false;
             if (_sm._areMultipleUnitsSelected)
             {
                 ClickOperations(3);
             }
             else
             {
                 ClickOperations(1);
             }            
         }
     }
 
     void ClickOperations(int caseNo)
     {
         RaycastHit hitInfo = new RaycastHit();
         bool _hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
 
         if (_hit)
         {
             switch (caseNo)
             {
                 case 0:
                     _sm.CheckOnLeftSingleClickConditions(hitInfo);
                     break;
 
                 case 1:
                     _sm.CheckOnRightSingleClickConditions(hitInfo);
                     break;
 
                 case 3:
                     _sm.CheckOnRightMultipleClickConditions(hitInfo);
                     break;
             }
         }
     }
 
     public List<GameObject> GetSelectedUnits()
     {
         return selectedObjects;
     }
 
     public bool IsWithinSelectionBounds(GameObject gameObject)
     {
         if (!_isSelecting)
             return false;
 
         var camera = Camera.main;
         var viewportBounds = Utils.GetViewportBounds(camera, _mousePosition1, Input.mousePosition);
         return viewportBounds.Contains(camera.WorldToViewportPoint(gameObject.transform.position));
     }
 
     void OnGUI()
     {
         if (_isSelecting)
         {
             var rect = Utils.GetScreenRect(_mousePosition1, Input.mousePosition);
             Utils.DrawScreenRect(rect, new Color(0.8f, 0.8f, 0.95f, 0.25f));
             Utils.DrawScreenRectBorder(rect, 2, new Color(0.8f, 0.8f, 0.95f));
         }
     }
 
 }
 
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

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

216 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

Related Questions

Taking continuously damage on a surface 0 Answers

SOME slider don't accept SOME variables... WHY??? 0 Answers

[BUG?] Vector3.Dot() product returns -1.47 1 Answer

GameObject array not showing on the inspector 0 Answers

How do I fix my UnityEngine Reference? 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