Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Runtime change of texture based on the POV of the player

Discussion in 'Scripting' started by ColmOF, Aug 21, 2015.

  1. ColmOF

    ColmOF

    Joined:
    Aug 21, 2015
    Posts:
    4
    Basically what I want to do is have a video texture change within the game when the person views the object that the texture is applied to. I think I can manage the runtime texture change but can this change happen based on the POV of the camera - like if x=co-ordinates y=co-ordinates then

    Onstart()
    {
    gameobject1.renderer.material.mainTexture = newTexture;
    }

    Does that make any sense?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    so if your player is looking at "thing x", "video x" plays in the UI or somewhere?
     
  3. ColmOF

    ColmOF

    Joined:
    Aug 21, 2015
    Posts:
    4
    Yeah like say if there are 2 televisions playing movie textures in the scene, the texture that they are playing changes as the player looks from one to the other.
    I guess I want the players view to start the video but then to change the video if they look back at it again
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    I'd probably go with a trigger collider to detect the player being close enough to interact.

    Assuming a FPS style player; you can then check the angle difference between the camera.main.transform.forward and (camera.main.transform.position - transform.position) i.e. the line between the object and the camera to see if the camera is pointing in it's direction (I'm always getting things like that the wrong way around, might be "transform position - camera position" but you get the idea)

    You'll need to handle "looking away" so you know if it's "still looking" or it's a "new look". Should be able to do that simply enough with a boolean.
     
  5. ColmOF

    ColmOF

    Joined:
    Aug 21, 2015
    Posts:
    4
    Hey, thanks for the replies. For what I'm thinking the players camera would be fixed, I was thinking of fixing a object to the camera's center so maybe I work a trigger collider through that, maybe overcomplicating things though. The camera.main.transform.position - transform.position sounds like the place to start.
    Thanks again
     
  6. ColmOF

    ColmOF

    Joined:
    Aug 21, 2015
    Posts:
    4
    http://benoculus.com/unity-3d/scrip...a-gameobject-at-runtime-in-unity-3d-pro-only/

    Found this blog that pretty much answers the question, just in case anyone stumbles across this,