本文整理汇总了C#中OTSprite.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# OTSprite.GetComponent方法的具体用法?C# OTSprite.GetComponent怎么用?C# OTSprite.GetComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OTSprite
的用法示例。
在下文中一共展示了OTSprite.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SpawnBattleship
private float timeSinceLastSpawn; //time since the last ship was spawned in seconds
#endregion Fields
#region Methods
void SpawnBattleship()
{
//create the game object
GameObject ship = OT.CreateObject("EnemyShipBattleship");
myShip = ship.GetComponent<OTSprite>();
//place it near the edge of the screen and in the high zone
float shipY = Random.value * (int)(SpaceZone.Top-SpaceZone.High)+(int)SpaceZone.High;
myShip.position = new Vector2(-50.0f,shipY);
myShip.renderer.enabled = true;
//Adjust the new ship's attributes based on level
EnemyShip shipLogic = (EnemyShip)myShip.GetComponent(typeof(EnemyShip));
shipLogic.moveSpeed = Battleship.moveSpeedBase+(Battleship.moveSpeedMultiplier*battleshipsLevel);
shipLogic.health = Battleship.healthBase+(int)(Battleship.healthMultiplier*battleshipsLevel);
Battleship battleshipLogic = (Battleship)myShip.GetComponent(typeof(Battleship));
battleshipLogic.reloadTimeBeam = Battleship.reloadTimeBeamBase-(Battleship.reloadTimeBeamMultiplier*battleshipsLevel);
battleshipLogic.reloadTimeBomb= Battleship.reloadTimeBombBase-(Battleship.reloadTimeBombMultiplier*battleshipsLevel);
battleshipLogic.beamDamage = Battleship.beamDamageBase+(int)(Battleship.beamDamageMultiplier*battleshipsLevel);
battleshipLogic.bombDamage = Battleship.bombDamageBase+(int)(Battleship.bombDamageMultiplier*battleshipsLevel);
battleshipLogic.projectileSpeed = Battleship.bombSpeedBase+(Battleship.bombSpeedMultiplier*battleshipsLevel);
battleshipLogic.resourceReward = Constants.BS_RESOURCE_REWARD;
Targets.enemyTargets.Add(myShip);
print(Targets.enemyTargets.Count);
}
示例2: Attack
void Attack()
{
//Only attack if there is something to attack
if (Targets.enemyTargets.Count > 0)
{
timeSinceLastShot = 0.0f;
//fire a player projectile towards an enemy ship
GameObject missile = OT.CreateObject("PlayerMissile");
myProjectile = missile.GetComponent<OTSprite>();
myProjectile.renderer.enabled = true;
// Pick a target, and fire at it
Vector2 target = Targets.PickRandomEnemyTarget().position;
target = new Vector2(target.x,target.y);
myProjectile.position = sprite.position;
//myProjectile.RotateTowards(target); //start the missiles off facing straight up
//Assign the projectile its atributes.
PlayerMissile pm = (PlayerMissile)myProjectile.GetComponent(typeof(PlayerMissile));
pm.damage = damage;
pm.speed = projectileSpeed;
pm.isHarvester = false;
pm.isSmart = false;
}
}
示例3: Attack
void Attack()
{
timeSinceLastShot = 0.0f;
//fire a player beam towards an enemy ship
GameObject beam = OT.CreateObject("PlayerBeam");
myProjectile = beam.GetComponent<OTSprite>();
myProjectile.renderer.enabled = false; //Beams appear after a short time in flight
// Pick a target, and fire at it
// TODO add target picking code for slug
Vector2 target = Targets.PickRandomEnemyTarget().position;
//We don't want the beams to be perfectly accurate, so offset the x and y by between (-1,1)
float offsetX = Random.value*2.0f-1.0f;
float offsetY = Random.value*2.0f-1.0f;
target = new Vector2(target.x+offsetX,target.y+offsetY);
myProjectile.position = sprite.position;
myProjectile.RotateTowards(target);
//Assign the projectile its atributes.
PlayerBeam pb = (PlayerBeam)myProjectile.GetComponent(typeof(PlayerBeam));
pb.damage = damage;
pb.maxFlightTime = flightTime;
pb.flightTime = 0.0f;
pb.isStun = true;
pb.stunDuration = stunDuration;
pb.isLaser = false;
}
示例4: Attack
void Attack()
{
//Determine if firing by picking a random number
if (Random.Range(0,101) <= shotCoefficient)
{
//Generate a projectile
GameObject bullet = OT.CreateObject("EnemyProjectile");
myProjectile = bullet.GetComponent<OTSprite>();
myProjectile.renderer.enabled = true;
// Pick a target, and fire at it
Vector2 target = Targets.PickRandomTargetFromAll().position;
myProjectile.position = sprite.position;
myProjectile.RotateTowards(target);
//Assign the projectile its atributes.
EnemyProjectile ep = (EnemyProjectile)myProjectile.GetComponent(typeof(EnemyProjectile));
ep.speed = projectileSpeed;
ep.damage = projectileDamage;
ep.attackType = attackType;
//Make shot unavailable
timeSinceLastShot = 0.0f;
}
}
示例5: Attack
void Attack()
{
timeSinceLastShot = 0.0f;
//fire a player projectile towards an enemy ship
GameObject bullet = OT.CreateObject("PlayerCannonProjectile");
myProjectile = bullet.GetComponent<OTSprite>();
myProjectile.renderer.enabled = true;
// Pick a target, and fire at it
Vector2 target = Targets.PickRandomEnemyTarget().position;
//We don't want the slugs to be very accurate, so offset the x and y by between (-2,2)
float offsetX = Random.value*4.0f-2.0f;
float offsetY = Random.value*4.0f-2.0f;
target = new Vector2(target.x+offsetX,target.y+offsetY);
myProjectile.position = sprite.position;
myProjectile.RotateTowards(target);
//Assign the projectile its atributes.
PlayerCannonProjectile pcp = (PlayerCannonProjectile)myProjectile.GetComponent(typeof(PlayerCannonProjectile));
pcp.damage = damage;
pcp.speed = projectileSpeed;
pcp.isFlak = false;
pcp.target = target;
pcp.isFlakShell = false;
pcp.isSuperFlak = true;
pcp.shellFlightTime = 0.5f;
}
示例6: RegisterGoon
public void RegisterGoon(OTSprite goon)
{
if(! _mob.Contains(goon))
{
_mob.Add(goon);
goon.GetComponent<MonsterManager>().SetMobManager(this);
}
}
示例7: Batch
public static void Batch(OTSprite sprite, OTSpriteBatch batch)
{
if (batch!=null)
{
OTBatching b = sprite.GetComponent<OTBatching>();
if (b==null)
b = sprite.gameObject.AddComponent<OTBatching>();
b.batch = batch;
b.Batch();
}
}
示例8: ConstructBeamCannon
/******* Turret Construction Methods ********/
void ConstructBeamCannon()
{
//Check to make sure the player has sufficient resources
if(gameState.currentResources >= Constants.BC_CONSTRUCTION_COST)
{
//Get a handle on the beamCannon's sprite, and make sure it shows up in the view
GameObject beamCannon = OT.CreateObject("BeamCannon");
myTurret = beamCannon.GetComponent<OTSprite>();
myTurret.position = sprite.position;
myTurret.renderer.enabled = true;
//Assign the beamCannon its default atributes.
BeamCannon turret = (BeamCannon)myTurret.GetComponent(typeof(BeamCannon));
turret.damage = Constants.DEFAULT_BC_DAMAGE;
turret.reloadTime = Constants.DEFAULT_BC_RELOAD_TIME;
turret.maxHealth = Constants.DEFAULT_BC_MAX_HEALTH;
turret.health = Constants.DEFAULT_BC_HEALTH;
turret.flightTime = Constants.DEFAULT_BC_FLIGHT_TIME;
//Spend the resources
gameState.currentResources -= Constants.BC_CONSTRUCTION_COST;
gameState.spentResources += Constants.BC_CONSTRUCTION_COST;
//Set this placement to be a beamCannon, instead of empty
isBeamCannon = true;
isEmptyPlacement = false;
//Drop the UI and unpause the game
Time.timeScale = 1.0f;
isUIActive = false;
gameState.isPlacementGUIActive = false;
}
else //Not enough resources
{
//do nothing....
//DESIGN CHOICE: Insufficient resources will make options greyed out.
}
}
示例9: Attack
void Attack()
{
//Determine if firing by picking a random number
if (Random.Range(0,101) <= shotCoefficient)
{
if (attackType == AttackType.Slug)
{
//Generate a projectile
GameObject bullet = OT.CreateObject("EnemyProjectile");
myProjectile = bullet.GetComponent<OTSprite>();
myProjectile.renderer.enabled = true;
// Pick a target, and fire at it
// TODO add target picking code for slug
Vector2 target = GameObject.Find("City").GetComponent<OTSprite>().position;
myProjectile.position = sprite.position;
myProjectile.RotateTowards(target);
//Assign the projectile its atributes.
EnemyProjectile ep = (EnemyProjectile)myProjectile.GetComponent(typeof(EnemyProjectile));
ep.speed = projectileSpeed;
ep.damage = projectileDamage;
ep.attackType = attackType;
//Make shot unavailable
shotAvailable = false;
timeSinceLastShot = 0.0f;
}
else if (attackType == AttackType.Beam)
{
//Generate a projectile
GameObject beam = OT.CreateObject("EnemyBeam");
myProjectile = beam.GetComponent<OTSprite>();
myProjectile.renderer.enabled = false; //Beams don't get rendered until they are in flight for a little bit
// TODO add target picking code for beam
Vector2 target = Targets.PickRandomTargetFromAll().position;
myProjectile.position = sprite.position;
myProjectile.RotateTowards(target);
//Assign the projectile its atributes.
EnemyBeam eb = (EnemyBeam)myProjectile.GetComponent(typeof(EnemyBeam));
eb.damage = projectileDamage;
eb.attackType = attackType;
//Make shot unavailable
shotAvailable = false;
timeSinceLastShot = 0.0f;
}
else //bomber
{
//Generate a projectile... TODO: Create EnemyBomb
GameObject bullet = OT.CreateObject("EnemyProjectile");
myProjectile = bullet.GetComponent<OTSprite>();
myProjectile.renderer.enabled = true;
//Bombs drop straight down
Vector2 target = new Vector2(sprite.position.x,-50.0f);
myProjectile.position = sprite.position;
myProjectile.RotateTowards(target);
//Assign the projectile its atributes.
EnemyProjectile ep = (EnemyProjectile)myProjectile.GetComponent(typeof(EnemyProjectile));
ep.speed = projectileSpeed;
ep.damage = projectileDamage;
ep.attackType = attackType;
//Make shot unavailable
shotAvailable = false;
timeSinceLastShot = 0.0f;
}
}
}
示例10: BeamAttack
void BeamAttack()
{
//Determine if firing by picking a random number
if (Random.Range(0,101) <= shotCoefficient)
{
for (int i = 0; i<3;i++)
{
//Generate a projectile
GameObject bullet = OT.CreateObject("EnemyBeam");
myProjectile = bullet.GetComponent<OTSprite>();
myProjectile.renderer.enabled = false;
Vector2 target = Targets.PickRandomTargetFromAll().position;
myProjectile.position = sprite.position;
myProjectile.RotateTowards(target);
//Assign the projectile its atributes.
EnemyBeam ep = (EnemyBeam)myProjectile.GetComponent(typeof(EnemyBeam));
ep.damage = beamDamage;
ep.attackType = AttackType.Beam;
//Make shot unavailable
timeSinceLastBeamShot = 0.0f;
}
}
}
示例11: BombAttack
void BombAttack()
{
//Determine if firing by picking a random number
if (Random.Range(0,101) <= shotCoefficient)
{
for (int i = 0; i<3;i++)
{
//Generate a projectile
float offsetX = i*1.4f - 0.7f;
GameObject bullet = OT.CreateObject("EnemyProjectile");
myProjectile = bullet.GetComponent<OTSprite>();
myProjectile.renderer.enabled = true;
Vector2 target = new Vector2(sprite.position.x+offsetX,-50.0f);
myProjectile.position = new Vector2(sprite.position.x+offsetX,sprite.position.y-1.0f);
myProjectile.RotateTowards(target);
//Assign the projectile its atributes.
EnemyProjectile ep = (EnemyProjectile)myProjectile.GetComponent(typeof(EnemyProjectile));
ep.speed = projectileSpeed;
ep.damage = bombDamage;
ep.attackType = AttackType.Bomb;
//Make shot unavailable
timeSinceLastBombShot = 0.0f;
}
}
}
示例12: SpawnCarrier
void SpawnCarrier()
{
//create the game object
GameObject ship = OT.CreateObject("EnemyShipCarrier");
myShip = ship.GetComponent<OTSprite>();
//place it near the edge of the screen and in the high zone
float shipY = Random.value * (int)(SpaceZone.Top-SpaceZone.Middle)+(int)SpaceZone.Middle;
myShip.position = new Vector2(-50.0f,shipY);
myShip.renderer.enabled = true;
//Adjust the new ship's attributes based on level
EnemyShip shipLogic = (EnemyShip)myShip.GetComponent(typeof(EnemyShip));
shipLogic.moveSpeed = Carrier.moveSpeedBase+(Carrier.moveSpeedMultiplier*carriersLevel);
shipLogic.health = Carrier.healthBase+(int)(Carrier.healthMultiplier*carriersLevel);
Carrier carrierLogic = (Carrier)myShip.GetComponent(typeof(Carrier));
carrierLogic.reloadTime = Carrier.reloadTimeBase-(Carrier.reloadTimeMultiplier*carriersLevel);
carrierLogic.projectileDamage = Carrier.projectileDamageBase+(int)(Carrier.projectileDamageMultiplier*carriersLevel);
carrierLogic.projectileSpeed = Carrier.projectileSpeedBase+(Carrier.projectileSpeedMultiplier*carriersLevel);
carrierLogic.resourceReward = Constants.CARRIER_RESOURCE_REWARD;
Targets.enemyTargets.Add(myShip);
print(Targets.enemyTargets.Count);
}
示例13: OrderStayIdle
private void OrderStayIdle(OTSprite goon)
{
goon.GetComponent<MonsterManager>().StayIdle();
}
示例14: OrderMove
private void OrderMove(OTSprite goon, Vector2 targetLocation)
{
goon.GetComponent<MonsterManager>().MoveToward(targetLocation);
}
示例15: ConstructMineralDrill
void ConstructMineralDrill()
{
//Check to make sure the player has sufficient resources
if(gameState.currentResources >= Constants.MD_CONSTRUCTION_COST)
{
//Get a handle on the beamCannon's sprite, and make sure it shows up in the view
GameObject mineralDrill = OT.CreateObject("MineralDrill");
myTurret = mineralDrill.GetComponent<OTSprite>();
myTurret.position = sprite.position;
myTurret.renderer.enabled = true;
//Assign the beamCannon its default atributes.
MineralDrill drill = (MineralDrill)myTurret.GetComponent(typeof(MineralDrill));
drill.maxHealth = Constants.DEFAULT_SLUG_MAX_HEALTH;
drill.health = Constants.DEFAULT_SLUG_HEALTH;
drill.resourceRate = Constants.DEFAULT_MD_RESOURCE_RATE;
//Spend the resources
gameState.currentResources -= Constants.MD_CONSTRUCTION_COST;
gameState.spentResources += Constants.MD_CONSTRUCTION_COST;
//Set this placement to be a beamCannon, instead of empty
isMineralDrill = true;
isEmptyPlacement = false;
//Drop the UI and unpause the game
Time.timeScale = 1.0f;
isUIActive = false;
gameState.isPlacementGUIActive = false;
}
else //Not enough resources
{
//do nothing....
//DESIGN CHOICE: Insufficient resources will make options greyed out.
}
}