本文整理汇总了C#中Transform.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.GetComponent方法的具体用法?C# Transform.GetComponent怎么用?C# Transform.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transform
的用法示例。
在下文中一共展示了Transform.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetTarget
public void SetTarget(Transform atk, Transform sel, bool fightBack, bool critiq)
{
attacker = atk;
ignoreList = new List<Transform>();
rc = Camera.mainCamera.GetComponent<RoundCounter>();
if(sel!=null){
target = sel;
foreach(Transform x in rc.AllChesses){
if(x != target){
ignoreList.Add(x);
}
}
}else{
if(attacker.GetComponent<CharacterProperty>().Player == 1){
ignoreList = rc.PlayerAChesses;
}else if(attacker.GetComponent<CharacterProperty>().Player == 2){
ignoreList = rc.PlayerBChesses;
}
}
fightBackMode = fightBack;
critiqHit = critiq;
excuted = false;
foreach(Transform chess in ignoreList){
Physics.IgnoreCollision(transform.collider, chess.collider);
}
}
示例2: GetFitPosition
public static Vector3 GetFitPosition(float x, float y, float z, Transform parent)
{
float parentRateX = parent.GetComponent<SpriteRenderer>().sprite.bounds.extents.x;
float parentRateY = parent.GetComponent<SpriteRenderer>().sprite.bounds.extents.y;
Vector3 fitPosition = new Vector3 (x*parentRateX, y*parentRateY, z);
return fitPosition;
}
示例3: OnEnable
void OnEnable()
{
if( !cameraTransform && Camera.main )
cameraTransform = Camera.main.transform;
if( !cameraTransform )
{
Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
enabled = false;
}
_target = transform;
if( _target )
{
controller = _target.GetComponent<ThirdPersonController>();
}
if( controller )
{
CharacterController characterController = (CharacterController)_target.GetComponent<Collider>();
centerOffset = characterController.bounds.center - _target.position;
headOffset = centerOffset;
headOffset.y = characterController.bounds.max.y - _target.position.y;
}
else
Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
}
示例4: Awake
void Awake(){
gameObject.name = gameObject.name.Replace("(Clone)", "");
Player = GameObject.FindWithTag("Player").transform;
hcs = Player.GetComponent<HeroControllerScript>();
inv = Player.GetComponent<Inventory>();
ItemObject = Resources.Load(gameObject.name) as GameObject;
}
示例5: Start
//Variables End___________________________________________________________
// Use this for initialization
void Start()
{
if(networkView.isMine == true)
{
//Store a reference to these objects since we will need to reference
//them frequently.
myTransform = transform.parent;
cameraHeadTransform = myTransform.FindChild("CameraHead");
resourceScript = myTransform.GetComponent<PlayerResource>();
changeScript = myTransform.GetComponent<ChangeWeapon>();
//Attaching a LineRenderer component which will give a visual
//effect for the block eraser. Only the player will be able to see it.
lineRenderer = gameObject.AddComponent<LineRenderer>();
lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
lineRenderer.SetColors(c1, c2);
lineRenderer.SetWidth(0.04f, 0.01f);
lineRenderer.SetVertexCount(2); //Start and end position.
}
else
{
enabled = false;
}
}
示例6: SetUILabel3
public static void SetUILabel3(Transform trans, string value, int quality)
{
trans.GetComponent<UILabel>().color = Color.white;
Color colorBianKuang = Color.white;
switch (quality)
{
case 1:
value = GetColorStr(value, "ffffff");
colorBianKuang = Color.black;
break;
case 2:
value = GetColorStr(value, "228833");
break;
case 3:
value = GetColorStr(value, "2e64dd");
break;
case 4:
case 5:
case 6:
value = GetColorStr(value, "a41cbb");
break;
}
trans.GetComponent<UILabel>().text = value;
trans.GetComponent<UILabel>().effectColor = colorBianKuang;
}
示例7: Start
void Start()
{
hand = GameObject.Find ("Handler");
C_light = this.transform.FindChild ("Light");
C_light.GetComponent<Light> ().range = 7;
C_light.GetComponent<CircleCollider2D> ().radius = 3.4f;
}
示例8: GUIRectWithObject
public static Rect GUIRectWithObject(Transform trans)
{
Vector3 cen = trans.GetComponent<Renderer>().bounds.center;
Vector3 ext = trans.GetComponent<Renderer>().bounds.extents;
Vector2[] extentPoints = new Vector2[8]
{
Camera.main.WorldToScreenPoint(new Vector3(cen.x-ext.x, cen.y-ext.y, cen.z-ext.z)),
Camera.main.WorldToScreenPoint(new Vector3(cen.x+ext.x, cen.y-ext.y, cen.z-ext.z)),
Camera.main.WorldToScreenPoint(new Vector3(cen.x-ext.x, cen.y-ext.y, cen.z+ext.z)),
Camera.main.WorldToScreenPoint(new Vector3(cen.x+ext.x, cen.y-ext.y, cen.z+ext.z)),
Camera.main.WorldToScreenPoint(new Vector3(cen.x-ext.x, cen.y+ext.y, cen.z-ext.z)),
Camera.main.WorldToScreenPoint(new Vector3(cen.x+ext.x, cen.y+ext.y, cen.z-ext.z)),
Camera.main.WorldToScreenPoint(new Vector3(cen.x-ext.x, cen.y+ext.y, cen.z+ext.z)),
Camera.main.WorldToScreenPoint(new Vector3(cen.x+ext.x, cen.y+ext.y, cen.z+ext.z))
};
Vector2 min = extentPoints[0];
Vector2 max = extentPoints[0];
foreach(Vector2 v in extentPoints)
{
min = Vector2.Min(min, v);
max = Vector2.Max(max, v);
}
return new Rect(min.x, min.y, max.x-min.x, max.y-min.y);
}
示例9: init
public void init(Transform newTarget)
{
target = newTarget;
if (target.GetComponent<NPC>() != null) {
isNPC = true;
npc = target.GetComponent<NPC>();
} else {
isNPC = false;
player = target.GetComponent<Player>();
}
if (isNPC) {
name.text = npc.name;
if (npc.isFriendly) {
name.color = NamePlate.COLOR_SELECTED;
} else {
name.color = NamePlate.COLOR_ENEMY;
}
} else {
name.text = player.name;
if (player.isFriendly) {
name.color = NamePlate.COLOR_SELECTED;
} else {
name.color = NamePlate.COLOR_ENEMY;
}
}
InvokeRepeating("updateHealth", 1f, 1f);
}
示例10: CalRecursion
//递归计算
private void CalRecursion(Transform father)
{
gameObjCount++;
if(father.renderer == null){
emptyObjCount++;
}else{
try{
faceCount += father.GetComponent<MeshFilter>().sharedMesh.triangles.Length / 3;
verticeCount += father.GetComponent<MeshFilter>().sharedMesh.vertexCount;
}catch{
Debug.LogError(father.name + "该物体不含有Mesh,请确认!");
}
}
if(father.childCount > 0){
foreach(Transform child in father){
if(child.childCount > 0){
CalRecursion(child);
}else{
gameObjCount++;
if(child.renderer == null){
emptyObjCount++;
}else{
try{
faceCount += child.GetComponent<MeshFilter>().sharedMesh.triangles.Length / 3;
verticeCount += child.GetComponent<MeshFilter>().sharedMesh.vertexCount;
}catch{
Debug.LogError(child.name + "该物体不含有Mesh,请确认!");
}
}
}
}
}
}
示例11: Update
// Update is called once per frame
void Update()
{
player1 = GameManager.gm.Frost;
player2 = GameManager.gm.Thornton;
player1lives.text = player1.GetComponent<Player>().lives.ToString();
player2lives.text = player2.GetComponent<Player>().lives.ToString();
if (player1 != null && player1.GetComponent<Player>().getWeapon() != null)
{
weapon1.sprite = player1.GetComponent<Player>().getWeapon().GetComponent<SpriteRenderer>().sprite;
player1weapon.text = player1.GetComponent<Player>().getWeapon().GetComponent<Weapon>().getChargesleft().ToString();
}
else {
weapon1.sprite = null;
player1weapon.text = null;
}
if (player2 != null && player2.GetComponent<Player>().getWeapon() != null)
{
weapon2.sprite = player2.GetComponent<Player>().getWeapon().GetComponent<SpriteRenderer>().sprite;
player2weapon.text = player2.GetComponent<Player>().getWeapon().getChargesleft().ToString();
}
else {
weapon2.sprite = null;
player2weapon.text = null;
}
}
示例12: GetClosetChess
public Transform GetClosetChess(Transform chess)
{
Transform target = null;
IList targets = new List<Transform>();
RoundCounter rc = transform.GetComponent<RoundCounter>();
if(chess.GetComponent<CharacterProperty>().Player==1){
foreach(Transform t in rc.PlayerBChesses){
if(!t.GetComponent<CharacterProperty>().death)
targets.Add(t);
}
}else{
foreach(Transform t in rc.PlayerAChesses){
if(!t.GetComponent<CharacterProperty>().death)
targets.Add(t);
}
}
Dictionary<float,Transform> sortDict = new Dictionary<float, Transform>();
if(targets.Count>0){
foreach(Transform t in targets){
float dis = Vector3.Distance(chess.transform.position, t.transform.position);
if(!sortDict.ContainsKey(dis))
sortDict.Add(dis, t);
}
var list = sortDict.Keys.ToList();
list.Sort();
target = sortDict[list[0]];
}else{
if(chess.GetComponent<CharacterProperty>().Player==1)
target = GameObject.Find("yellow-tower").transform;
else
target = GameObject.Find("red-tower").transform;
}
return target;
}
示例13: Act
public override void Act(Transform player, Transform npc)
{
//Set the target position as the player position
destPos = player.position + new Vector3(0.0f, 1.0f, 0.0f);
npc.GetComponent<AICarController>().throttle = 1.0f;
//Calculate the steering value
Vector3 RelativeWaypointPosition = npc.InverseTransformPoint(new Vector3(destPos.x, npc.position.y, destPos.z));
npc.GetComponent<AICarController>().steer = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude;
//Initialise the weapon controller for attack state
if (!bAIWeaponInitialised)
{
weapon = npc.GetComponent<AIWeaponController>();
npcTransform = npc;
bAIWeaponInitialised = true;
}
Transform turret = weapon.Turret;
Quaternion turretRotation = Quaternion.LookRotation(destPos - turret.position);
turret.rotation = Quaternion.Slerp(turret.rotation, turretRotation, Time.deltaTime * curRotSpeed);
//Shoot shouldn't call every frame
if (!bStartShooting)
{
//Shoot bullet/Missiles towards the player
ShootShells();
bStartShooting = true;
}
}
示例14: Action
/// <summary>
/// For this one we are going to copy all the jumping data from the player.
/// </summary>
/// <param name="p_Actor"></param>
public override void Action(Transform p_Actor)
{
if(m_Rigidbody == null)
m_Rigidbody = p_Actor.GetComponent<Rigidbody>();
//todo: save this to stop getting the ref every frame
float groundLvl = p_Actor.GetComponent<Civilian>().m_GroundLevel;
//keep jumping
if (p_Actor.position.y > groundLvl)
{
m_Rigidbody.velocity += Vector3.down * Time.deltaTime * PlayerController.Instance.m_FallSpeed;
}
else if (p_Actor.position.y <= groundLvl)
{
m_ElapsedTimeGround += Time.deltaTime;
if (m_ElapsedTimeGround > m_MaxTimeLanded)
{
m_Rigidbody.velocity = Vector3.up * PlayerController.Instance.m_JumpForce;
m_ElapsedTimeGround = UnityEngine.Random.Range(0.0f, m_MaxTimeLanded);
}
}
}
示例15: Start
protected override void Start()
{
base.Start ();
//nextAttackTime = Time.time;
currentState = State.Chasing;
mPathFinder = GetComponent<NavMeshAgent> ();
skinMaterial = GetComponent<Renderer> ().material;
GameObject player = GameObject.FindGameObjectWithTag ("Player");
if (player)
{
hasTarget = true;
target = player.transform;
targetEntity = target.GetComponent<LivingEntity> ();
targetEntity.OnDeath += OnTargetDeath;
//mTargetCollisionRadius = target.GetComponent<CapsuleCollider> ().radius;
mTargetCollisionRadius = target.GetComponent<CharacterController> ().radius;
mCollisionRadius = GetComponent<CapsuleCollider> ().radius;
StartCoroutine (UpdatePath ());
}
}