Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm facing a problem, please help me if it is possible.
I'm practicing unity and I'm trying to make sth for myself. And I'm playing a video using UI and canvas raw image and what I need is this:
I want to tell animator to start a special animation when the movie reaches a specific frame or time for example when it reaches at 10 seconds I want to make the movie stop and that animation be triggered.
I don't have any problem with playing or pausing my video or triggering animations in animators...
My problem is that I don't know how to get the number of current frame playing in movie using script
I tried using time functions to solve my problem but it has two disadvantages , first its not accurate !! each time it results in a small different out come and I don know exactly why , second it becomes hard if I change something else for example actions before that movie
In short my question is this: is there any way to get the current frame number of a movie using script in unity ? ( a movie which is playing using UI and canvas and raw image )
Thanks a lot in advance...
Is there any way to get the current frame number of a movie using
script in unity ?
Yes. You can obtain the current video frame with the VideoPlayer.frame variable.
Note that it works like an array index. 0 is the first frame and 1 is the second frame.
You seem to confuse video frame with video time in the title of this question. They are two different stuff.
You can obtain the video time with VideoPlayer.time. You just check when it is 10 seconds in the Update function then do something.
VideoPlayer vidPlayer = null;
void Update()
{
if (vidPlayer.time == 10)
{
///
}
}
See here for how to play video with the VideoPlayer API.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 days ago.
Improve this question
I am currently working on a Unity Game , so basically it is a school project ,but next level . I build an arena , and two balls on it . The balls have to push each other on the arena and the last one standing on the arena wins . But i am stuck with my code ... i want that the first ball who falls down , immediatly to respawn the both balls in the respawn point , and then the score to go higher with 1 point every time one of the balls falls down. It seems so difficult for me and i am struggling with it. If anybody cand save me i will be happy ! Thanks !! <3
I tried a lot of methods but the only bug i have is that if a ball falls down , the game automatically spawns a lot of balls in the place the ball has fallen . And after 1 minute my map is full of balls .... and i do not want that to happen. So please i am asking for your help !
Assuming you have two ball objects, you could make a Player.cs script, that is applied to the two balls. The script could have the following fields:
The other player object
The player's score object
The position on which the player is to respawn
Then, inside your Update method, you could check whether the ball has fallen below a certain Y value. If so, it can get the other player's score object, and increase the number on it. After that, just set the position of the current object to the specified position.
Currently, I can't provide any specific APIs or code, since I don't have Unity installed, but I'll be sure to edit the answer as soon as it installs.
For what you want to do, my advice is to create an empty GameObject, add a collider, and activate the isTriggered property. To make a previously prepared vector2 or vector3 the position of the players when one of the players is triggered and to set all the forces affecting the rigidbody of the players to 0 . You can also figure out which player to score according to the tag of the triggered GameObject every time it is triggered.
I'm not a professional but I hope it helped.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
so, a little backstory. I have been working on a cel shaded 3d rpg for a while now. it' s going to have the options to switch between action based and turn based. that's for a later time though.
the question I have is I want to add a way to damage the enemy when the sword collides with it. I know onCollisionEnter is a way to do it, I also know raycasts are a different but more complicated way to do it.
I want for each sword swing to damage the enemy (Slimes for now, more enemies later.) incremently instead of an instant death. I have tried onCollisionEnter before, but couldn't get it to decrease in increments.
just, well... an instant death
the onCollisionEnter I have used is with the comparetag<> function.
it might also be important to know that I am on unity 2019.4.X
I have tried to use unity 2020.x but it was too taxing on my PC, as every time I would do something an application load thing would appear and it would be annoying.
Raycasts is not suitable for you if you are not throwing swords. You are using the correct way (collision), but you are missing a point:
This does not happen once when there is a collision. Lots of collisions happen consecutively.
To avoid this, you can close one of the colliders for a short time when there is a collision. (this means that: If the enemy has 100 health and we are decreasing 20 health with each hit, more than 5 collisions occur consecutively. Therefore, we are killing the enemy in one fell swoop.)
Or you can use a bool value (for example swordSwingCollisionActive). If the collision occurs after the sword is swung, you set this bool value to true. When the sword swing is over, you go false again. Just write if (swordSwingCollisionActive) return; at the beginning of OnCollisionEnter.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am total beginner in C#, except that I went through the Microsoft courses and finished some basic projects. Now I thought to try something on my own, creating a very basic business simulation game with a c# form in Visual Studio.
I asked Google but had a hard time to find what I am looking for. I do basically want to start off with a system that simulates days. Let's say I have a button that I can press to play forward, and when I do this, a pre-defined date like 1 January 2017 should increase with +1 day ticks as long as I don't click on that button again to pause the game. This is for example how it works in the game Europa Universalis IV, except that I can even increase the speed by 5 levels in that game, but this would be a bit too much now.
I just want to understand how the basic concept of a simulated date in economy based, or strategy based games is working. I featured out that they do even use 28 days in February in Europa Universalis IV... so, how is the time or date game logic working. I'd like to create this system too to understand it. I guess I need a form project, 1 button, 1 timer and 1 label.
Can someone point me into the right direction?
Several things.
You need a timer to drive this.
You probably want to run increments smaller than 1 day, say 1 hour
This is a VERY rough outline
On button click, timer.Enabled = !timer.Enabled (this reverses the timer state, you probably want to update UI and such as well)
In the timer_Elapsed event, you want to update your game state (e.g. _now = _now.AddHours(1); UpdateState(); UpdateUI();)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to learn C#, so I decided to make a little game where monsters siege you. The problem is, I draw the character by using fillrectangle, and same for the trees. The trees start with a random location. They're supposed to stay at the location they first appeared in, but with the code I'm using, they get a new location every timer tick. Help?
If you want the trees to stay at the same location, you should tell your program to do so.
Because you provided no code samples we can just assume you redraw your scene every timer-tick and you might draw the just random-generated locations of the trees at every tick event, a solution like suggested by others is to generate the random coordinates of the trees before you draw the first time, save those coordinates and then when you redraw in your tick event those coordinates will still be the same coordinates as before so your trees will hold position. You might want to read an article about 2d development that explains the 3 basic steps of:
Setting everything up/Initialize objects etc and draw the first
scene.
Calculate what changes between 2 shown pictures are made.
Draw
the new picture/Update.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am working on one project where I stuck on one point where I have to run two methods in parallel.
In Function 1
In my application what I am doing is I am grabbing images from the IP cam and storing that image into the one folder.
This function is used for continues streaming of camera.
For this you can refer this question which I have asked IP Camera stops streaming.
In Function 2
I will pick images from the path where my Function2 is dumping images.
Here I am doing some other operations like:
Save Image captured from the IP Camera
Detect faces in Image
Draw Face markers on Image
Some database based on result of Face Detection
Delete image File
Function 2 takes more execution time than Function 1.
So for this purpose after searching on google I get to know I can do this by multithreading.
So, I am little bit confused about this and as I am new in c# I am not that much aware of multithreading.
So, can anyone help me out on this?
You do indeed need to use multithreading, and in your case it should not be too difficult.
You'll need to add a "using System.Threading;" to the start of any files that involve threading.
public void Function1()
{
//Do camera stuff
Image image = MagicalCameraStuff();
//Create a thread that the processing will occur on
Thread process = new Thread(() => Function2(image));
//Start the thread
process.Start();
}
public void Function2(Image i)
{
//Do some processing without blocking the main thread
}
More information on threading:
http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx