Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#pragma strict
var target : Transform;
function Start () {
	
}

function Update () {

	if(target.active){
		gameObject.transform.position.x= target.transform.position.x;
		gameObject.transform.position.z= target.transform.position.z;
		
		 

	}
}


What I have tried:

#pragma strict
var target : Transform;
function Start () {
	
}

function Update () {

	if(target.active){
		gameObject.transform.position.x= target.transform.position.x;
		gameObject.transform.position.z= target.transform.position.z;
		
		 

	}
}

transform.active = false;
     else{
     transform.active = true;
     }
Posted
Updated 14-Dec-17 0:50am

Transform does not appear to have such a property according to Unity - Scripting API: Transform[^].
 
Share this answer
 
You could try:
C#
GameObject targetObject = target.gameObject;
if (targetObject.activeSelf) {
   // ...
}

and
C#
targetObject.SetActive(true /* or false */);

Also, the code block you showed is not well formed, you have an else statement outside of any function nor related to any if statement. I would be surprised this would even compile.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900