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 ArthurKhu · May 03, 2015 at 09:22 PM · javascript

In game TV set.

Hello. I have some TV model, like alt text

and C# code

 using UnityEngine;
 using System.Collections;
 
 public class ClicktoPlayWebMovieClass : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
 
     private Vector3 FindBoundCord (int i, GameObject _GameObject){
         /*This is basically where the code starts. It starts out by creating a 
            * bounding box around the target GameObject. 
           It calculates the 8 coordinates forming the bounding box, and 
           returns them all to the for loop.
           Because there are no real method which returns the coordinates 
           from the bounding box I had to create a switch/case which utillized 
           Bounds.center and Bounds.extents.*/
         
         Bounds _TargetBounds = _GameObject.GetComponent<Renderer>().bounds;
         Vector3 _TargetCenter = _TargetBounds.center;
         Vector3 _TargetExtents = _TargetBounds.extents;
         
         
         switch(i){
         case 0:
             return _TargetCenter + new Vector3(_TargetExtents.x, _TargetExtents.y, _TargetExtents.z); 
         case 1:
             return _TargetCenter + new Vector3(_TargetExtents.x, _TargetExtents.y, _TargetExtents.z*-1);
         case 2:
             return _TargetCenter + new Vector3(_TargetExtents.x, _TargetExtents.y*-1, _TargetExtents.z);
         case 3:
             return _TargetCenter + new Vector3(_TargetExtents.x, _TargetExtents.y*-1, _TargetExtents.z*-1);
         case 4:
             return _TargetCenter + new Vector3(_TargetExtents.x*-1, _TargetExtents.y, _TargetExtents.z);
         case 5:
             return _TargetCenter + new Vector3(_TargetExtents.x*-1, _TargetExtents.y, _TargetExtents.z*-1);
         case 6:
             return _TargetCenter + new Vector3(_TargetExtents.x*-1, _TargetExtents.y*-1, _TargetExtents.z);
         case 7:
             return _TargetCenter + new Vector3(_TargetExtents.x*-1, _TargetExtents.y*-1, _TargetExtents.z*-1);
         default:
             return Vector3.zero;
         }
         
     }
 
     IEnumerator MyMethod() {
         //Debug.Log("Before Waiting 2 seconds");
         yield return new WaitForSeconds(2);
         //Debug.Log("After Waiting 2 Seconds");
     }
 
     public string url = "http://becunningandfulloftricks.files.wordpress.com/2013/04/hedgehog_in_the_fog.ogg";
     
     // Update is called once per frame
     void Update () {
 
 
         if (Input.GetMouseButtonDown (0)) {
             Debug.Log("clicked");
             // Start download
             var www = new WWW(url);
             // Make sure the movie is ready to start before we start playing
             var movieTexture = www.movie;
             while (!movieTexture.isReadyToPlay) {
                 StartCoroutine(MyMethod());
             }
 
             print("LOADED!!!");
 
             Vector2 _ObjectScreenCord, _Xmin = new Vector2(Screen.width,0), _Xmax = Vector2.zero, _Ymin = new Vector2(Screen.height,0), _Ymax = Vector2.zero;
             float _Height, _Width;    
             
             
             for(int i = 0; i != 8; i++){
                 //FindBoundCord() locates the eight coordinates that forms the boundries, followed by converting the coordinates to screen space.
                 // The entire script starts in FindBoundCord
                 _ObjectScreenCord = Camera.main.WorldToScreenPoint(FindBoundCord(i, transform.gameObject));
                 
                 /* After gathering the coordinates and converting them to screen space
               we try to locate which of these have the highest/minimum x and y values.
              The difference between highest/minimum x and y must correspond to
               width and height.*/
                 
                 if(_ObjectScreenCord.x > _Xmax.x){
                     _Xmax.x = _ObjectScreenCord.x;
                 }
                 else if(_ObjectScreenCord.x < _Xmin.x){
                     _Xmin.x = _ObjectScreenCord.x;
                 }    
                 if(_ObjectScreenCord.y > _Ymax.x){
                     _Ymax.x = _ObjectScreenCord.y;
                 }
                 else if(_ObjectScreenCord.y < _Ymin.x){
                     _Ymin.x = _ObjectScreenCord.y;
                 }            
             }
             
             
             
             //Too measure the distance between them, I use the Vector2 method Distance.
             _Height = Vector2.Distance(_Ymax, _Ymin);
             if (_Height > Screen.height || _Height < 0){
                 _Height = 0;
             }
             
             _Width = Vector2.Distance(_Xmax, _Xmin);
             if (_Width > Screen.width || _Width < 0){
                 _Width = 0;
             }
 
             print(_Height+" - "+_Width);
 
 
             GetComponent<Renderer>().material.mainTexture = movieTexture;
             // Assign clip to audio source
             // Sync playback with audio
             GetComponent<AudioSource>().clip = movieTexture.audioClip;
             // Play both movie & sound
 
             GUITexture gt = GetComponent<GUITexture>();
             gt.texture = movieTexture;
 
 
             transform.localScale = new Vector3 (0f,0f,0f);
             transform.position = new  Vector3 (0.5f,0.5f,0f);
 
             Rect r = gt.pixelInset;
             
 
             print(_Width);
             print(movieTexture.width / 2);
 
             r.xMin = -_Width / 2;
             r.xMax = _Width / 2;
             r.yMin = -_Height / 2;
             r.yMax = _Height / 2;
 
 //            r.xMin = -movieTexture.width / 2;
 //            r.xMax = movieTexture.width / 2;
 //            r.yMin = -movieTexture.height / 2;
 //            r.yMax = movieTexture.height / 2;
 
             gt.pixelInset=r;            
             movieTexture.Play();
             GetComponent<AudioSource>().Play();
         }
     }
 
 }

When I'am clicking on my TV set, looks good: alt text

It looks good until I am not rotate my camera. After camera rotation movieTexture has initial position on the screen:

alt text

and it makes my TV set broken... How to specify movieTexture, that it must have position of the GetComponent().material.mainTexture? I need make to look something like this

alt text

But instead of screen of the TV must be video of the movieTexture at it must rotate, like screen of the TV set...

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 HD32 · May 04, 2015 at 10:21 AM

I don't know exactly how to fix this, but you might try adding a separate camera and canvas that would individually render that plane as its own GUI. Good luck =)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Move Object by dragging (mobile) makes the balls fall from the cup 1 Answer

Functions being ignored 2 Answers

Unity3d Update issue 2 Answers

making a trail that destroys enemies 1 Answer

Issue in Build APk and Export through Script 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