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 /
avatar image
0
Question by The-Z-axis · Feb 09, 2019 at 01:31 AM · #pragma

2D sprite and 3D model- swap visibility upon keystroke

Hey everyone, new user to Unity here. I'm working on a prototype for a new game where one of the main mechanics will be the player character swapping between a 2D sprite on the ground to a 3D model and vice versa upon hitting a key. Right now I have both objects moving in tandem and was wondering how I could set the visibility of the 3D model to start as false and swap between the sprite and model upon hitting a key like the spacebar.

Again, this is all fairly new to me, ESPECIALLY navigating C#, so spare no detail, I yearn to learn!

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 Crumpet · Feb 09, 2019 at 03:55 AM 0
Share

Like just disabling the renderer for the sprite while the model is active and then the opposite while you want the model active?

avatar image The-Z-axis Crumpet · Feb 09, 2019 at 05:17 AM 0
Share

Precisely. If it turns out to be something super easy to do that would be grand. If it takes a lot of scripting, a detailed description of what each line does would really help me learn.

2 Replies

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

Answer by Crumpet · Feb 09, 2019 at 05:23 AM

that's very simple. Everything you can click/tick/adjust in the editor is simple to do with a script in unity. you'd just be looking for

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class renderer : MonoBehaviour
 {
     public SpriteRenderer sprenderer;
     public MeshRenderer meshrenderer;
     public bool tickme = false;
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update ()
     {
         //if blah blah blah happens
         if (tickme)
         {
             sprenderer.enabled = false;
             meshrenderer.enabled = true;
         }
         else
         {
             sprenderer.enabled = true;
             meshrenderer.enabled = false;
         }
     }
 }
 

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 Crumpet · Feb 09, 2019 at 05:30 AM 0
Share

Or if you are looking to disable the whole object, use GameObject and set them to active would be similar code just using public GameObjects and ins$$anonymous$$d using gameobject.setactive(true) or gameobject.setactive(false)

avatar image
0

Answer by The-Z-axis · Feb 09, 2019 at 05:47 AM

Awesome!! Once I assigned the items I needed it worked great! One last question, how would I make it so that hitting the space bar check/unchecks "Tickme"?

Comment
Add comment · Show 2 · 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 Crumpet · Feb 09, 2019 at 06:38 AM 0
Share
 if(Input.getkeyDown(keycode.Space)
 {
     Tickme = !Tickme;
 }

didnt use a compiler and can't remember where capslock letters are so just rewrite it.

avatar image Crumpet Crumpet · Feb 09, 2019 at 06:42 AM 0
Share

the unity script reference is pretty good so if you wanna know stuff its all on there for example if you want to know how to get mouse position you can google and it will come up with examples its good for simple stuff like this.

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

98 People are following this question.

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

Related Questions

How i destroy the object of that part that collides with another object? 2 Answers

How to make keywords per material works properly (not in Editor) 0 Answers

スクリプトが追加できません。,スクリプトクラスが見つからない (I can't add a script. , Script class not found) 0 Answers

Failed to re-package resources Facebook-unity-sdk-7.11.1 2 Answers

Is it possible to have a changing line of script based off of variables? 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