- Home /
Can't change properties of one object by using another object's information
I have two problems with my code right now. Both issues seem to be the same thing.
Example 1: I want to change the color of a Text object. SetColor(Color c) has one line of code:
this.transform.GetComponent<Text>().color = c;
It works perfectly fine if I try to change the color like this:
var p = Instantiate(object);
p.SetColor(Color.blue);
However, it creates blank Text objects if I code it like this:
var p = Instantiate(object);
p.SetColor(something.color);
In another object, I want a particle system to "explode" confetti when it gets hit. It put confetti wherever I want if I hard code the numbers like this:
var _confetti = Instantiate(confetti);
_confetti.transform.position = new Vector3(5, 5, 50);
However, if I want it to appear where the object is? Nada. It still shows up on the screen, but it just shows up in the same location every time:
var _confetti = Instantiate(confetti);
_confetti.transform.position = this.transform.position;
I have a feeling these issues are related. Does anyone see what I'm doing wrong?
And you're certain that those values are incorrect? I.e. is the color property of something actually set to a value you want when you call this piece of code?
Your answer
Follow this Question
Related Questions
Scene items are not showing in hierarchy nor in scene window in unity 5 0 Answers
Close unity activity and start another activity - android 0 Answers
toggling isKinematic not working Unity5, works in 4.6.6 1 Answer
[UNET] PlayerPrefab successfully spawns on Server, but Clients only see their own playerPrefab. 0 Answers