本文整理汇总了C#中Transform类的典型用法代码示例。如果您正苦于以下问题:C# Transform类的具体用法?C# Transform怎么用?C# Transform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transform类属于命名空间,在下文中一共展示了Transform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
// Awake
void Awake()
{
myRigidbody = GetComponent<Rigidbody>();
myRigidbody.maxAngularVelocity = 25f;
myTransform = GetComponent<Transform>();
cameraTransform = Camera.main.GetComponent<Transform>();
}
示例2: OnCollisionWithEnemy
protected void OnCollisionWithEnemy(GameObject enemy, float power)
{
power *= WeaponPowerMiltiplier;
enemyTransform = enemy.transform;
enemyController = enemy.GetComponent<FightEnemyController>();
if (power < MinForceToHit)
return;
// Blood
newBloodParticle = Instantiate<GameObject>(BloodParticles);
newBloodParticle.transform.position = enemyTransform.position;
newBloodParticle.transform.up = (enemyTransform.position - selfTransform.position).normalized;
Destroy(newBloodParticle, 1);
// Do damage
enemyController.DoDamage(Mathf.Clamp(power, MinForceToHit, MaxForceToHit));
//print(WeaponTypeName + ": " + hitVelocityMagnitude.ToString());
// Damage Text
newDamageText = Instantiate<GameObject>(DamageText);
newDamageTextText = newDamageText.GetComponent<Text>();
newDamageTextText.rectTransform.SetParent(WorldCanvas, false);
newDamageTextText.rectTransform.position = enemyTransform.position + new Vector3(0f, 0.5f, 0f); ;
newDamageTextText.text = string.Format("{0}", power.ToString("F0"));
}
示例3: AddChain
//add chain into chains list
public void AddChain(Transform chain)
{
//if chains list isn't created, create it
if(chains == null)
chains = new List<Transform>();
//if linerenderer isn't added, add it
if(lineRend == null)
{
lineRend = GetComponent<LineRenderer>();
if(!lineRend)
{
lineRend = gameObject.AddComponent<LineRenderer>();
lineRend.material = ropeMaterial;
}
}
chains.Add (chain); //add chain into chains list
//fill LineRenderer component's positions
lineRend.SetVertexCount (chains.Count);
lineRend.SetPosition (chains.Count - 1, chains[chains.Count - 1].position);
startChainCount = chains.Count;
}
示例4: CrossToTarget
public static float CrossToTarget(Transform thisXform, Vector3 targetPos)
{
Vector3 nominalPos = thisXform.position;
Vector3 DirToTarget = (targetPos - nominalPos).normalized;
Vector3 ForwardDir = thisXform.forward.normalized;
return Vector3.Cross(ForwardDir, DirToTarget).y;
}
示例5: DrawLayoutOutline
void DrawLayoutOutline(Transform t) {
var layout = t.GetComponent<tk2dUILayout>();
if (layout != null) {
Vector3[] p = new Vector3[] {
new Vector3(layout.bMin.x, layout.bMin.y, 0.0f),
new Vector3(layout.bMax.x, layout.bMin.y, 0.0f),
new Vector3(layout.bMax.x, layout.bMax.y, 0.0f),
new Vector3(layout.bMin.x, layout.bMax.y, 0.0f),
new Vector3(layout.bMin.x, layout.bMin.y, 0.0f),
};
for (int i = 0; i < p.Length; ++i) p[i] = t.TransformPoint(p[i]);
Handles.color = Color.magenta;
Handles.DrawPolyLine(p);
var sizer = t.GetComponent<tk2dUILayoutContainerSizer>();
if (sizer != null) {
Handles.color = Color.cyan;
float arrowSize = 0.3f * HandleUtility.GetHandleSize(p[0]);
if (sizer.horizontal) {
Handles.ArrowCap(0, (p[0] + p[3]) * 0.5f, Quaternion.LookRotation(p[1] - p[0]), arrowSize);
Handles.ArrowCap(0, (p[1] + p[2]) * 0.5f, Quaternion.LookRotation(p[0] - p[1]), arrowSize);
} else {
Handles.ArrowCap(0, (p[0] + p[1]) * 0.5f, Quaternion.LookRotation(p[3] - p[0]), arrowSize);
Handles.ArrowCap(0, (p[2] + p[3]) * 0.5f, Quaternion.LookRotation(p[0] - p[3]), arrowSize);
}
}
}
for (int i = 0; i < t.childCount; ++i)
DrawLayoutOutline(t.GetChild(i));
}
示例6: Shot
public override void Shot (Vector3 shotOrigin, GameObject target, Transform cannonTransform)
{
//if(WeaponReady)
{
WeaponReady = false;
Vector3 shotDirection = cannonTransform.forward;
// Note: In a real project, you must not instante many objects a runtime, instead, you may consider creating a shoot pool.
Rigidbody newBullet = Instantiate(bullet,shotOrigin,cannonTransform.rotation) as Rigidbody;
newBullet.AddForce(shotForce*shotDirection);
if(shotSound != null && shotAudioSource != null)
shotAudioSource.PlayOneShot(shotSound);
if(weaponParticleSystem != null)
weaponParticleSystem.Play();
StartCoroutine(LightFlash());
// Reset timmer
timeCounter = 0f;
}
}
示例7: CalculateAbsoluteWidgetBounds
/// <summary>
/// Calculate the combined bounds of all widgets attached to the specified game object or its children (in world space).
/// </summary>
public static Bounds CalculateAbsoluteWidgetBounds(Transform trans)
{
UIWidget[] widgets = trans.GetComponentsInChildren<UIWidget>() as UIWidget[];
Bounds b = new Bounds(trans.transform.position, Vector3.zero);
bool first = true;
foreach (UIWidget w in widgets)
{
Vector2 size = w.relativeSize;
Vector2 offset = w.pivotOffset;
float x = (offset.x + 0.5f) * size.x;
float y = (offset.y - 0.5f) * size.y;
size *= 0.5f;
Transform wt = w.cachedTransform;
Vector3 v0 = wt.TransformPoint(new Vector3(x - size.x, y - size.y, 0f));
// 'Bounds' can never start off with nothing, apparently, and including the origin point is wrong.
if (first)
{
first = false;
b = new Bounds(v0, Vector3.zero);
}
else
{
b.Encapsulate(v0);
}
b.Encapsulate(wt.TransformPoint(new Vector3(x - size.x, y + size.y, 0f)));
b.Encapsulate(wt.TransformPoint(new Vector3(x + size.x, y - size.y, 0f)));
b.Encapsulate(wt.TransformPoint(new Vector3(x + size.x, y + size.y, 0f)));
}
return b;
}
示例8: TryGiveItem
/// <summary>
/// tries to award an item to a recipient by transform, item type
/// and amount
/// </summary>
public static bool TryGiveItem(Transform recipient, vp_ItemType itemType, int amount)
{
if (recipient == null)
{
Debug.LogError("Error (" + Instance + ") Recipient was null.");
return false;
}
vp_Inventory inventory;
if (!m_RecipientInventories.TryGetValue(recipient, out inventory))
{
inventory = vp_TargetEventReturn<vp_Inventory>.SendUpwards(recipient, "GetInventory");
m_RecipientInventories.Add(recipient, inventory);
}
if (inventory == null)
{
Debug.LogError("Error (" + Instance + ") Failed to find an enabled inventory on '" + recipient + "'.");
return false;
}
if (TryMatchExistingItem(inventory, recipient, itemType, amount))
return true;
return TryGiveItemAsNew(recipient, itemType, amount);
}
示例9: StateAgro
public StateAgro(NavMeshAgent _agent, Vector3 _point, Transform _transform, ref StateSet _set)
{
set = _set;
transform = _transform;
agent = _agent;
point = _point;
}
示例10: Start
// Use this for initialization
void Start()
{
player = PlayerController.MyTransform;
candig = false;
diggableItem.SetActive(false);
digtime = 0f;
}
示例11: AddChildren
private void AddChildren(Transform parent, List<Transform> list)
{
list.Add (parent);
foreach (Transform t in parent) {
AddChildren (t, list);
}
}
示例12: Start
// Use this for initialization
void Start()
{
//make a reference with the transform component
this._transform = gameObject.GetComponent<Transform>();
this.Reset();
}
示例13: Awake
private void Awake()
{
button = transform.FindChild("Button");
thebase = transform.FindChild("Base");
startScale = button.localScale;
targetScale = thebase.localScale;
}
示例14: Start
void Start()
{
_t = transform;
_animator = GetComponent<Animator>();
_controller = GetComponent<CharacterController>();
_rigidbody = GetComponent<Rigidbody>();
}
示例15: Awake
// Use this for initialization
void Awake()
{
player = GameObject.FindGameObjectWithTag ("Player").transform;
playerOrgin = player.position;
path2 = new []{ new Vector3(10.0f,20.0f,40f), new Vector3(10f,10f,20f),
playerOrgin, new Vector3(0f,10f,-10f), new Vector3( 0f, -5f, -20f), new Vector3(10f,-10f,5f),
new Vector3(5f,5f,15f), new Vector3(0f,20f,20f)};
path3 = new []{ new Vector3(30.0f,6.0f,60f), new Vector3(9f,40f,40f),
new Vector3(15.2f,2f,20f), new Vector3(0f,0f,5f), new Vector3( 4f, 7f, -30f), new Vector3(16f,4f, 5f)};
path4 = new []{ new Vector3(20.0f,30.0f,60f), new Vector3(5f,70f,40f),
new Vector3(28.2f,21f,20f), new Vector3(0f,0f,5f), new Vector3( 4f, 7f, -30f), new Vector3(16f,4f, 5f)};
path5 = new []{ new Vector3(20.0f,30.0f,60f), new Vector3(5f,-70f,30f),
new Vector3(11.2f,16f,20f), new Vector3(0f,0f,5f), new Vector3( 4f, -17f, -30f), new Vector3(16f,4f, 5f)};
aiShip = FindObjectOfType <Rigidbody> ();
launcher = GetComponent<MLauncher> ();
path = path2;
target = path[0];
bound = new Bounds (path[0], new Vector3(1f,1f,1f));
}