本文整理汇总了C#中Weapon.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Weapon.GetComponent方法的具体用法?C# Weapon.GetComponent怎么用?C# Weapon.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Weapon
的用法示例。
在下文中一共展示了Weapon.GetComponent方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setWeapon
public void setWeapon (Weapon weapon)
{
weapon.transform.parent = gameObject.transform;
weapon.gameObject.layer = 3;
weapon.gameObject.transform.localPosition = new Vector3(0.25f,-0.2f);
weapon.gameObject.transform.localEulerAngles = new Vector3(0,0);
weapon.gameObject.transform.localScale = new Vector3 (1,1,1);
weapon.isSet = true;
weapon.GetComponent<Renderer>().sortingOrder = 3;
weapon.GetComponent<SpriteRenderer>().sprite = weapon.EquipedSprite;
weapon.tag = "enemyWeapon";
}
示例2: Init
// note: ProjectileContainers contain simple dummy values, which are
// then replaced by data that's passed-in via projectile objects
void Init(Weapon incoming)
{
weapon = incoming;
weaponType = incoming.weaponType;
alreadyCollided = false;
iconSprite = incoming.iconSprite;
title = incoming.title;
damage = incoming.damage;
hp = incoming.hp;
rateOfAttack = incoming.rateOfAttack;
spriteRenderer.sprite = incoming.carriedSprite;
speed = incoming.speed;
maxDistance = incoming.maxDistance;
lob = incoming.lob;
lobGravity = incoming.lobGravity;
fadeIn = incoming.fadeIn;
collider2D.enabled = true;
origin = new Vector3(transform.position.x, transform.position.y, transform.position.z);
// initialize animation controller if projectile is animated
if (incoming.GetComponent<Weapon>().animatedProjectile)
{
anim = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate
(Resources.Load(("Sprites/Projectiles/" + incoming.name + "_0"), typeof(RuntimeAnimatorController)));
animator.runtimeAnimatorController = anim;
animator.speed = .5f;
}
InvokeRepeating("CheckDistanceTraveled", 1, 0.3F);
}
示例3: GotHit
public void GotHit(Weapon shooter)
{
if(isJuggernaut)
{
shooter.GetComponent<Player>().SetPlayerAsJuggernaut();
}
//AudioSource.PlayClipAtPoint(deathSound.clip, transform.position, deathSound.volume);
_scoredMessages.Clear();
deaths++;
Player sp=null;
//string verb = DeathMessenger.Instance.GetRandomVerb();
var killMessage = DeathMessenger.Instance.GetRandomMessage();
if(shooter != null) {
//set death message for me, and score for scorer
sp = shooter.GetComponent<Player>();
sp.SetScoredMessage(string.Format(killMessage.killerMessage, name, sp.name));
if(GameSystem.Instance.CurrentGameMode != GameSystem.GameMode.Elimination) {
var plShoot = shooter.GetComponent<Player>();
if(GameSystem.Instance.CurrentGameMode != GameSystem.GameMode.Juggernaut || (isJuggernaut || plShoot.isJuggernaut))
plShoot.ScoreUp();
}
}
var rag = (GameObject)Instantiate(ragdoll, transform.position, transform.rotation);
rag.GetComponentInChildren<Renderer>().material.color = col;
_weapon.InstantReload();
foreach (var rigid in rag.GetComponentsInChildren<Rigidbody>())
{
rigid.AddForce(rigidbody.velocity, ForceMode.VelocityChange);
var characterJoint = rigid.GetComponent<CharacterJoint>();
if(characterJoint)
Destroy(characterJoint, 14.95f);
Destroy(rigid, 15);
}
GetRespawnCamera().Activate(this, string.Format(killMessage.victimMessage, name, sp.name), new Rect(crosshairRect.center.x - Screen.width / 4.4f, crosshairRect.center.y, Screen.width / 2.2f, Screen.height / 15f));
}
示例4: OnTriggerEnter2D
void OnTriggerEnter2D(Collider2D col)
{
if (col.GetComponent<Bullet>() != null && col.tag == "Enemy")
{
Debug.Log("Player hit");
//Health--;
}
if (currentItem == null && col.GetComponent<StashItem>() != null)
{
currentItem = col.GetComponent<StashItem>();
}
if (currentItem != null && col.GetComponent<PlayerStash>() != null)
{
col.GetComponent<PlayerStash>().ReturnItem(currentItem);
currentItem = null;
}
if (col.GetComponent<Weapon>() != null)
{
if (!col.name.Contains(CurrentWeapon.name))
{
Destroy(CurrentWeapon.gameObject);
CurrentWeapon = col.GetComponent<Weapon>();
CurrentWeapon.GetComponent<Collider2D>().enabled = false;
CurrentWeapon.GetComponent<SpriteRenderer>().enabled = false;
CurrentWeapon.start();
}
else
{
CurrentWeapon.GetComponent<Collider2D>().enabled = false;
CurrentWeapon.GetComponent<SpriteRenderer>().enabled = false;
CurrentWeapon.Upgrade();
Destroy(col.gameObject);
}
}
}
示例5: CacheAndSetupWeapons
void CacheAndSetupWeapons()
{
// WEAPON GAMEOBJECT'S 'WEAPON' COMPONENT
// ~~~~~~~~~~~~~~~~~~~~~~~~
// cache specific weapons (Sword, Hammer, etc) via parent class 'Weapon'
// use to call currently equipped weapon animations
leftWeapon = weaponBelt[left].GetComponent<Weapon>();
equippedWeapon = weaponBelt[equipped].GetComponent<Weapon>();
rightWeapon = weaponBelt[right].GetComponent<Weapon>();
// set weapons to player's WeaponCollider layer
weaponBelt[left].layer = 9;
weaponBelt[equipped].layer = 9;
weaponBelt[right].layer = 9;
// disable animations for weapons that are not equipped
leftWeapon.EnableAnimation(false);
equippedWeapon.EnableAnimation(true);
rightWeapon.EnableAnimation(false);
// disable colliders for all weapons - they are only enabled during attacks
leftWeapon.GetComponent<BoxCollider2D>().enabled = false;
equippedWeapon.GetComponent<BoxCollider2D>().enabled = false;
rightWeapon.GetComponent<BoxCollider2D>().enabled = false;
// fade in newly equipped weapon
float fadeAfter = 0f;
float fadeTime = .2f;
SpriteRenderer upperSprite = equippedWeapon.transform.Find("Upper").GetComponent<SpriteRenderer>();
SpriteRenderer centerSprite = equippedWeapon.transform.Find("Center").GetComponent<SpriteRenderer>();
SpriteRenderer lowerSprite = equippedWeapon.transform.Find("Lower").GetComponent<SpriteRenderer>();
upperSprite.DOKill();
centerSprite.DOKill();
lowerSprite.DOKill();
MFX.Fade(upperSprite, 1f, fadeAfter, fadeTime);
MFX.Fade(centerSprite, 1f, fadeAfter, fadeTime);
MFX.Fade(lowerSprite, 1f, fadeAfter, fadeTime);
// fade out newly stashed weapons
FadeOutStashedWeapons(leftWeapon);
FadeOutStashedWeapons(rightWeapon);
}
示例6: PickUp
void PickUp(Weapon w)
{
//if (Input.GetKeyDown (KeyCode.E) && !player.pickUp) {
if (Input.GetMouseButtonDown(0) && !player.pickUp) {
switch(w.type)
{
case WeaponType.MAIN:
player.activeWeapon = 1;
break;
case WeaponType.DISTANCE:
player.activeWeapon = 2;
break;
case WeaponType.MINOR:
player.activeWeapon = 3;
break;
}
player.GetMyAnimator().SetInteger("WeaponType", player.activeWeapon);
if (player.currentWeapon != null)
{
player.HideWeapon();
}
//weapon transformation
w.transform.position = hand.weaponPivot.transform.position; w.transform.SetParent(hand.weaponPivot.transform);
w.transform.rotation = hand.weaponPivot.transform.rotation;
w.transform.localRotation = Quaternion.Euler(new Vector3(0, 90, 0));
w.WeaponOriginalRotation = w.transform.rotation;
w.isActive = false;
w.GetComponent<BoxCollider>().enabled = false;
weaponIsActive = false;
hand.myAnimator.enabled = true;
hand.myAnimator.SetBool("Show Weapon", true);
hand.myAnimator.SetBool("Show Weapon Closer", true);
StartCoroutine(Wait(w));
//player.pickUp = true;
//player.pickedUpWeapon = w;
}
}
示例7: FadeOutStashedWeapons
void FadeOutStashedWeapons(Weapon stashedWeapon)
{
float fadeAfter = 0f;
float fadeTime = .2f;
SpriteRenderer stashedSprite = stashedWeapon.GetComponent<SpriteRenderer>();
stashedSprite.DOKill();
MFX.Fade(stashedSprite, 0f, fadeAfter, fadeTime);
}
示例8: CacheAndSetupWeapons
void CacheAndSetupWeapons()
{
// WEAPON GAMEOBJECT'S 'WEAPON' COMPONENT
// ~~~~~~~~~~~~~~~~~~~~~~~~
// cache specific weapons (Sword, Hammer, etc) via parent class 'Weapon'
// use to call currently equipped weapon animations
leftWeapon = weaponBelt[left].GetComponent<Weapon>();
equippedWeapon = weaponBelt[equipped].GetComponent<Weapon>();
rightWeapon = weaponBelt[right].GetComponent<Weapon>();
// set correct names for weapon gameObjects
weaponBelt[left].name = "Left";
weaponBelt[equipped].name = "Equipped";
weaponBelt[right].name = "Right";
// set weapons to correct layers
weaponBelt[left].layer = PLAYER_LAYER;
weaponBelt[equipped].layer = PLAYER_LAYER;
weaponBelt[right].layer = PLAYER_LAYER;
// set weapons to correct sorting layers;
weaponBelt[left].GetComponent<SpriteRenderer>().sortingLayerName = HERO_WEAPON_SORTING_LAYER;
weaponBelt[equipped].GetComponent<SpriteRenderer>().sortingLayerName = HERO_WEAPON_SORTING_LAYER;
weaponBelt[right].GetComponent<SpriteRenderer>().sortingLayerName = HERO_WEAPON_SORTING_LAYER;
// set weapon colliders to correct layers
weaponBelt[left].transform.Find("MeleeCollider").gameObject.layer = WEAPON_COLLIDER;
weaponBelt[equipped].transform.Find("MeleeCollider").gameObject.layer = WEAPON_COLLIDER;
weaponBelt[right].transform.Find("MeleeCollider").gameObject.layer = WEAPON_COLLIDER;
// set pickup colliders to correct layers
weaponBelt[left].transform.Find("PickupCollider").gameObject.layer = PICKUP_LAYER;
weaponBelt[equipped].transform.Find("PickupCollider").gameObject.layer = PICKUP_LAYER;
weaponBelt[right].transform.Find("PickupCollider").gameObject.layer = PICKUP_LAYER;
// disable SpriteRenderer for weapons that are not equipped
leftWeapon.spriteRenderer.enabled = false;
equippedWeapon.spriteRenderer.enabled = true;
rightWeapon.spriteRenderer.enabled = false;
// disable colliders for all weapons - they are only enabled during attacks
leftWeapon.GetComponent<BoxCollider2D>().enabled = false;
equippedWeapon.GetComponent<BoxCollider2D>().enabled = false;
rightWeapon.GetComponent<BoxCollider2D>().enabled = false;
// fade in newly equipped weapon
float fadeAfter = 0f;
float fadeTime = .2f;
SpriteRenderer equippedSprite = weaponBelt[equipped].GetComponent<SpriteRenderer>();
equippedSprite.DOKill();
MFX.Fade(equippedSprite, 1f, fadeAfter, fadeTime);
// fade out newly stashed weapons
FadeOutStashedWeapons(leftWeapon);
FadeOutStashedWeapons(rightWeapon);
SetWeaponAnimations(equippedWeapon);
}
示例9: Update
// Update is called once per frame
void Update()
{
noise.SetActive(false);
//face mouse
mouse = Camera.main.ScreenToWorldPoint (Input.mousePosition);
mouse.z = 0;
transform.rotation = Quaternion.LookRotation (Vector3.forward, transform.position - mouse);
//move
Vector3 vel = new Vector3 ();
if (Input.GetKey (KeyCode.W)) {
Vector3 velUp = new Vector3 ();
// just use 1 to set the direction.
velUp.y = 0.5f;
vel += velUp;
//rb.AddForce (transform.forward * Time.deltaTime);
} else if (Input.GetKey (KeyCode.S)) {
Vector3 velDown = new Vector3 ();
velDown.y = -0.5f;
vel += velDown;
}
// Combinations of up/down and left/right are fine.
if (Input.GetKey (KeyCode.A)) {
Vector3 velLeft = new Vector3 ();
velLeft.x = -0.5f;
vel += velLeft;
} else if (Input.GetKey (KeyCode.D)) {
Vector3 velRight = new Vector3 ();
velRight.x = 0.5f;
vel += velRight;
}
// check if player wants to move at all. Don't check exactly for 0 to avoid rounding errors
if (vel.magnitude > 0.001) {
Vector3.Normalize (vel);
vel *= speed;
rb.velocity = vel;
animator.SetTrigger ("walk");
} else {
animator.SetTrigger ("stopWalk");
}
//fire
if (Input.GetMouseButtonDown (0)) //LEFT CLICK
fireWeapon ();
else if (Input.GetMouseButtonDown (1))
dropWeapon ();
//pick up weapon
if (Input.GetKeyDown (KeyCode.E)) {
RaycastHit2D hit = Physics2D.Raycast (transform.position, Vector3.down, 100, 1 << 15); //WEAPON LAYER
if (!weapon && hit.collider != null){
reloadSound.Play();
weapon = hit.collider.gameObject.GetComponent<Weapon> ();
SpriteRenderer weaponSprite = weapon.GetComponent<SpriteRenderer>();
weaponSprite.enabled = false;
weapon.gameObject.layer = gameObject.layer;
weaponImg.sprite = weapon.heldImg;
}
}
}
示例10: DropComparedWeapon
public void DropComparedWeapon(Weapon weapon)
{
if (weapon != null)
{
weapon.transform.SetParent(null);
weapon.transform.position = body.transform.position + new Vector3(0, 0.1f, 0);
weapon.transform.rotation = Quaternion.Euler(0, 0, 270);
weapon.isActive = true;
weapon.GetComponent<Raycasting>().enabled = true;
weapon.GetComponent<BoxCollider>().enabled = true;
//pickedUpWeapon = null;
TurnOffStrings(weapon);
}
}
示例11: updateWeaponAnimation
private void updateWeaponAnimation(Weapon w, bool moving)
{
// Ensure that a weapon exists for us to update
if (w == null)
{
return;
}
Animator weapAnimator = w.GetComponent<Animator>();
if (weapAnimator != null)
{
weapAnimator.SetBool(animMoving, moving);
}
}
示例12: Update
/// <summary>
/// Sets the Movement of the Player, allows it to fire, drift, and boost.
/// </summary>
void Update()
{
if (victor) {
gameObject.layer = 11;
}
if (poweredOn) {
//Linear Movement
if (enemyAI != null)
{
horiz = enemyAI.horizontal;
vert = enemyAI.vertical;
}
else
{
horiz = Input.GetAxis (horizAxis + playerNum.ToString ()) * speed;
vert = Input.GetAxis (vertAxis + playerNum.ToString ()) * speed;
}
//Angular Movement
if (Mathf.Abs (horiz) > minInput || Mathf.Abs (vert) > minInput) {
float angle = Mathf.Atan2 (vert, horiz) * Mathf.Rad2Deg + 90;
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.AngleAxis (angle, Vector3.forward), Time.deltaTime * rotationSpeed);
}
//New Thrust Adjustment (drift)
if (enemyAI != null)
{
thrust = enemyAI.drift;
}
else
{
thrust = Input.GetAxis (thrustButton + playerNum.ToString ());
}
if (thrust <= 0)
{
man0Drag = 1;
man1Drag = 1;
man2Drag = 1;
movement = new Vector2 (horiz, vert);
rb.AddForce (movement);
}
else
{
man0Drag = 0;
man1Drag = 0;
man2Drag = 0;
}
//Shield Recharge Adjustment
if (useShieldRecharge && canRecharge && canBoost) {
StartCoroutine ("ShieldRecharge", shieldChargeRate);
}
//Boosting
if (canBoost && thrust <= 0 && shield > minShieldForBoost) {
playerInputBoost = false;
if (enemyAI != null)
{
playerInputBoost = enemyAI.boost;
}
else if (Input.GetAxis (boostButton + playerNum.ToString ()) > 0.3f)
{
playerInputBoost = true;
}
if (playerInputBoost) {
canBoost = false;
StartCoroutine("Boost");
}
}
//Shooting
if (canFire && ((Input.GetAxis (fireButton + playerNum.ToString ()) > 0.3f) || (enemyAI != null && enemyAI.fire)))
{
canFire = false;
//default weapon
if (weapons.Count == 0)
{
fireRate = defaultFireRate;
laserObject = (GameObject)Instantiate (defaultLaser, laserInstatiationPoint.transform.position, transform.rotation);
weaponIconImage.sprite = defaultWeaponIcon;
laserObject.GetComponent<WeaponFire> ().AttachPlayer (this.gameObject);
StartCoroutine ("RegulateWeaponFire");
}
else
{
//power up weapon
currentWeapon = weapons [weapons.Count - 1];
weaponIconImage.sprite = currentWeapon.GetComponent<SpriteRenderer> ().sprite;
fireRate = currentWeapon.fireRate;
if (currentWeapon.isDual) {
laserObject = (GameObject)Instantiate (currentWeapon.laserType, dualLaserInstatiationPoint1.transform.position, transform.rotation);
if (laserObject.GetComponent<WeaponFire> () == null) {
laserObject.GetComponentInChildren<WeaponFire> ().AttachPlayer (this.gameObject);
} else {
//.........这里部分代码省略.........