• 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
0
Question by AAcat · Apr 24, 2016 at 04:25 AM · error messagealpha-channelconverting

converting JS to C# for Alpha channels and animation

I am trying to convert this JS to C#. this is my JS that i made

 #pragma strict
 
 var whateverglow : UnityEngine.Animator;
 var hashthingglow : int = Animator.StringToHash("StartGlow");
 var logovis : float;
 
 function Start () {
  whateverglow = GetComponent("Animator");
 }
 
 function Update () {
     GetComponent(SpriteRenderer).color.a = logovis; //change logovis variable between 0-1 to tell how clear it is.
    whateverglow.SetTrigger (hashthingglow);
 }

And this is what I have converted it to but there seems to be a error in line 18 (I'm not too familiar with C#)

 using UnityEngine;
 using System.Collections;
 
 
 public class logoclass : MonoBehaviour {
 
 
     UnityEngine.Animator whateverglow;
     int hashthingglow = Animator.StringToHash("StartGlow");
     float logovis;
 
 
     void  Start (){
         whateverglow = GetComponent<Animator>();
     }
 
     void  Update (){
         GetComponent<SpriteRenderer>().color.a = logovis; //this doesn't seem right.
         whateverglow.SetTrigger (hashthingglow);
     }
 }


The error i get is: C:\Users\Owner\Google Drive\Game\Game\Assets\GameScripts\NewBehaviourScript.cs(3,3): Error CS1612: Cannot modify the return value of 'UnityEngine.SpriteRenderer.color' because it is not a variable (CS1612) (Assembly-CSharp)

Comment
Add comment
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

1 Reply

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

Answer by TBruce · Apr 25, 2016 at 01:17 AM

@AAcat

Try this

 using UnityEngine;
 using System;
 
 
 public class LogoClass:MonoBehaviour
 {
     
     public Animator whateverglow;
     public int hashthingglow = Animator.StringToHash("StartGlow");
     public float logovis;
     
     public void Start()
     {
         whateverglow = GetComponent<Animator>();
     }
     
     public void Update()
     {
         var tmp_cs1 = GetComponent<SpriteRenderer>().color;
         tmp_cs1.a = logovis;
         GetComponent<SpriteRenderer>().color = tmp_cs1; //change logovis variable between 0-1 to tell how clear it is.
         whateverglow.SetTrigger (hashthingglow);
     }
 }
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

56 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

Related Questions

I have an error on a C# script @username 2 Answers

Error upon rebooting Unity - "Associated script cannot be loaded" How can I resolve this? 2 Answers

Object reference not set to instance of an object? 0 Answers

Error status 0xc0000020 unity 5.4.0f3 2 Answers

I Need help with scripting a first person camera? 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