So, I'm new to Unity and am trying to set the size of a Video Player, but this task seems so dificult.
Basically I'm loading my video from file using this:
videoPlayer.url = path;
Where the path is a variable that has the path of the video I'm using.
When my video is loaded into the player, it takes all the screen and I can't find a way to set the player dimension to like 100x100.
Found a way to set the dimension using a second camera.
Put my videoplayer inside the cam and set its viewport rect to they way I needed.
I think there has to be an easier way but this worked!
Related
So, I made a sprite that is half long an HD screen, but when I import that in Unity and I add it to the scene it's larger than half the screen. I already set the camera resolution to 1920x1080. How can I solve this?
It isn't the size of image that matters, but the container in which it is to be placed. Adjust the size of your Image using Rect Tool and Rect Transform.
I'm trying to load all the sprites given the current sprite in the sprite renderer on an object however I am unable to load each individual sprite (2d sprite with multiple 'frames', i.e. a spritesheet) no matter what I try.
I've used
Resources.LoadAll<Sprite>(AssetDatabase.GetAssetPath(spriteRenderer.sprite.GetInstanceID()).Replace(".png", ""));
And even
Resources.LoadAll<Sprite>(Path);
But I can't seem to get it to load the things I want (usually it doesn't work at all but on an older version of Unity it loaded circular loading bars and error signs). I have created the frames/sub-sprites of the sprite.
I've tried changing the path to just using the sprite's name to including the filetype to anything else but nothing works.
I am using Unity 2019.1.0f2 if that matters.
So you want to load a bunch of sprites right?
Have you tried this?
Sprite[] loadedSprites = Resources.LoadAll("Sprites", typeof(Sprite));
If you use this your unity must have a folder named Resources. Basically what it says inside LoadAll at the first param is this: "Resources/Sprites" and then it looks for all Types that are a Sprite inside the Sprite folder.
Note: Make sure all the .png files that are planned to be used are signed as Sprite(2D and UI) this can be done by clicking of the png in unity and right corner it wil say Texture Type.
It ended up being a simple misunderstanding.
My folders were all inside the "Assets" folder while they should have been in the "Assets/Resources" folder. Now I can load the sprite renderer's sprite's sprites using
spriteRenderer.sprite.GetInstanceID()).Replace(".png","").Replace("Assets/Resources/","")
It's a bit long but it works!
Thanks to Louis Ingenthron for the hint!
I am working on a Unity project that requires me to download a video file (mp4 format) and play it using the VideoPlayer component. Because the file is downloaded at runtime, I effectively have to "stream" it via a url to its downloaded location, as opposed to loading it as a VideoClip.
To accurately size the target RenderTexture and GameObject the video will be playing to, I need the dimensions of the video file itself. Because it is not a VideoClip I cannot use:
VideoClip clip = videoPlayer.clip;
float videoWidth = clip.width;
float videoHeight = clip.height;
Because I am using a source URL as opposed to a VideoClip, this will return null.
Can I get the video dimensions directly from the file somehow?
You can retrieve these information from the Texture that VideoPlayer constructs.
Get VideoPlayer
VideoPlayer videoPlayer = GetComponent<VideoPlayer>();
Get the Texture VideoPlayer
Texture vidTex = videoPlayer.texture;
Get VideoPlayer dimension width/height
float videoWidth = vidTex.width;
float videoHeight = vidTex.height;
Make sure to only get the texture after videoPlayer.isPrepared is true. See my other answer for full code on how to play video make it display on RawImage component.
image size = 2048 x 512px
as what shown on image i uploaded
I don't know what happened with my 2d sprite many people say that was compress problem but i still can't fix it and i tried to use unity asset store 2D pack its look good in my unity, someone ever got the same?
i used photo shop to make these 2D sprite, i used brushes, burn and dodge tools.
public GameObject background;
I need to load one specific animation clip from .fbx file and play it in loop.
I tried this:
GameObject go = Instantiate(Resources.Load("Animations/ubohost")) as GameObject;
ubohost.fbx is file with model and animation clip called mixiamo.com.
Then I am sure that I should add the animation to the gameobject:
Animation anim = go.AddComponent<Animation>();
And after that somehow add a clip, I tried many ways, but none works.
I know that it should be really easy, but I am not getting anywhere.
Basically I need just to load and play one animation with script.