Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by ridet · May 08, 2017 at 02:19 PM · c#image

How can I display an image/ video from the script ?

Hi, I am a new user and would like to know how to display an image in the scene from the script. I have a picture series in a folder on my computer and wish to display an image at a specific time. When the player shoots the displayed image I want to remove it and display another one. Is it possible to do this under Unity? If so, would it be possible to help me? Thank you

Comment
Add comment · Show 2
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
avatar image Mentoliptus · May 16, 2017 at 08:35 AM 0
Share

Can you post some code and details about your scene structure for people to be able to help you?

avatar image ridet · May 16, 2017 at 11:42 PM 0
Share

Hello, Thank you for your reply. Indeed, I try to adapt an existing game (Unity Cookie 2D Space Shooter) to create one according to my needs (see attached file). I want to display a spaceship in the middle of my scene and display rocks, the player has to shoot the rocks and when the rock disappears I want to display at the same location of the rock an image among the images present on my disc. I would like to know how I can do that? Any help / direction is welcome. Thank you @$$anonymous$$entoliptus

link text

c.txt (4.9 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Mentoliptus · May 17, 2017 at 06:42 AM

There a multiple ways of achieving what you described, but I think it is best to do it with prefabs. If you are not familiar with them, look in the Unity manual and in the Unity tutorials to get the basics.

First create a prefab with an Image component that is your desired image from disk.

Then declare a class variable for your prefab (it can be a specific type or just GameObject) and add the creation of you prefab in the DestroyRock() method. Something like this:

 public GameObject destroyedRockPrefab;
 
 IEnumerator DestroyRock()
 {
     gameManager.GetComponent<GameManager>().UpdateScore(score);
     yield return new WaitForSeconds(0.2f);
 
     // instantiate prefab on the same coordinates as the destroyed rock
     var destroyedRock = Instantiate(destroyedRockPrefab, gameObject.transform.position, gameObject.transform.rotation);
     
     Destroy(gameObject);
 }

Here are some more resources about instantiating prefabs at runtime: Unity manual and Unity scripting reference. I hope they will help you with your game.

Let me mention that I did the same thing for my first game, took one finished game from a tutorial and modified it to meet my vision. Line by line you learn and will be able to create a game from scratch. 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
avatar image
0

Answer by ridet · Jun 12, 2017 at 10:45 PM

Hello Mentoliptus Thank you very much for your light, it works very well. I have a second question if you can help me this would be very appreciated. Instead of the images I would like to display small video in .mov format. I exported them into my asset folder and add a Gameobject> UI> RawImage with the RawImage texture video. However I would like to display the video where the rock is displayed as the last time. I can not put the canvas / RawImage in the same place of rock when it disappears. Would you know how I could do it? Any help will be welcome. Thanks again in advance for your help. @Mentoliptus

[1]: /storage/temp/95836-c1.txt


c1.txt (809 B)
Comment
Add comment · Show 1 · 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
avatar image Mentoliptus · Jun 16, 2017 at 09:08 AM 0
Share

Hi @ridet , sorry for the late replay, but I will have no time to be online for a week or two (my son was born a few days ago) so I suggest that you post this as a new question so others can answer it. Please tag me in the new question so if nobody answers you question, I'll answer it as soon as I can. Thank you your understanding. Good luck!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SetActive dosen't work 0 Answers

File.WriteAllBytes problem 0 Answers

onClick Event for UI Text? 1 Answer

Image not appearing after transferring build to Mac from PC? 0 Answers

ERROR CS0119 C# GetComponent< > 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