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 shads11858 · Oct 30, 2013 at 03:29 AM · editorgridprojectprojector

Projector working in Editor, but disappearing after Build & Run

This is a bit of strange one I think and not sure why it's not working.. I created a projector using scripts for a terrain grid sqr so it would follow the mouse and highlight the grid tile that a ray hits. Works great when I run the game using play button inside Unity editor, but as soon as I build and run the project as exe, the projector isn't there anymore and not sure why. I'll copy in some of the code I've got for it.

 private float brushSize = 4.0f;
 private Texture2D brushes;
 private int brushSizePaint = 3;
 
 void Start(){
 brushes = Resources.LoadAssetAtPath("Assets/PATileTerrain/Brushes/patileterrain_brush1.png", typeof(Texture2D)) as Texture2D;
 
 InitPreview();
 }
 
     public void InitPreview(){ 
 
         
         GameObject previewObject = new GameObject("PATileTerrainPreview");
         previewObject.hideFlags = HideFlags.HideInHierarchy;
         previewProjector = previewObject.AddComponent<Projector>();
         previewProjector.nearClipPlane = terrain.settings.minHeight - 1.0f;
         previewProjector.farClipPlane = terrain.settings.maxHeight + 1.0f;
         previewProjector.orthographic = true;
         previewProjector.orthographicSize = brushSize;
         previewProjector.transform.Rotate(-90.0f, 0.0f, 0.0f);
          
         Shader previewShader = Shader.Find("Hidden/PATileTerrainPreview");
           Material previewMaterial = new Material(previewShader);
         previewMaterial.SetColor("_Color", new Color(0.32f, 0.36f, 0.6f, 0.07f));
         previewMaterial.SetTexture("_Brush", brushes);
         previewProjector.material = previewMaterial;
         
         previewProjector.enabled = true;
         
         /*[1.04]*/ previewProjector.transform.parent = terrain.transform; 
     }
 
     public void UpdatePreview()
     {
         if (previewProjector)
         { 
             
             previewProjector.nearClipPlane = terrain.settings.minHeight - 1.0f;
                 previewProjector.farClipPlane = terrain.settings.maxHeight + 1.0f;
                 previewProjector.material.SetColor("_Color", new Color(0.32f, 0.36f, 0.6f, 0.97f));
                 previewProjector.material.SetTexture("_Brush", brushes);
                 
             
             if (show3x3){
                 previewProjector.orthographicSize = (terrain.settings.tileSize * 0.6f)* brushSizePaint;
             
             }else previewProjector.orthographicSize = terrain.settings.tileSize * 0.6f;
             }
 }
 
     void Update () 
     {
         // ** THIS SECTION GETS POINTS using raycasts & x,y for tile seleciton ** 
         RaycastHit hit;
         Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
         Physics.Raycast(ray, out hit, Mathf.Infinity);
         int x, y;
         Vector3 pos;
         pos = terrain.transform.InverseTransformPoint(hit.point);
         x = (int)Mathf.Abs(pos.x / terrain.tileSize);
         y = (int)Mathf.Abs(pos.z / terrain.tileSize);
         // ** THIS SECTION GETS POINTS ** 
             
         //uses the previewProjector created object to show highlighted grid sqr.
         PATileTerrain.PATile selectedTile = terrain.GetTile(x,y); //called every update so tile position is used in IF statement to update mousemovement
         //as long as tile and projector are assigned values, show highlighted projector on map.        
         if (selectedTile != null && previewProjector != null){
             previewProjector.transform.position = terrain.transform.TransformPoint(selectedTile.position);
             previewProjector.transform.rotation = terrain.transform.localRotation;
             previewProjector.transform.Rotate(90.0f, 0.0f, 0.0f);
         }//end if on projector.
 }
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

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

Repainting while performing asset operations 5 Answers

How to highlight or select an asset in project window from editor script? 2 Answers

GRID missing - Editor Scene View - 5.0.1f1 - not a duplicate 0 Answers

Multiple object Selection in project view: Unity shows wrong type 0 Answers

Is there a way to create custom Game templates? 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