Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Cobalt60 · Aug 04, 2012 at 02:12 AM · projectileturret

Possibility of adding More than One Projectile

Well I have a turret script here but I was wondering if I can possibly have the script shoot more than one projectile randomly. Any help, points in direction or answers are greatly appreciated. Thanks for the looking, Sincerely Cobalt60

pragma strict

var myProjectile : GameObject; var reloadTime : float = 1f; var turnSpeed : float = 5f; var firePauseTime : float = .25f; var errorAmount : float = .001; var myTarget : Transform; var muzzlePositions : Transform[]; var pivot_Tilt : Transform; var pivot_Pan : Transform; var aim_Pan : Transform; var aim_Tilt : Transform;

private var nextFireTime : float;

function Start () {

}

function Update () { if(myTarget) { aim_Pan.LookAt(myTarget); aim_Pan.eulerAngles = Vector3(0, aim_Pan.eulerAngles.y,0); aim_Tilt.LookAt(myTarget);

  pivot_Pan.rotation = Quaternion.Lerp(pivot_Pan.rotation, aim_Pan.rotation,Time.deltaTime*turnSpeed);
  pivot_Tilt.rotation = Quaternion.Lerp(pivot_Tilt.rotation, aim_Tilt.rotation,Time.deltaTime*turnSpeed);
  
    if(Time.time >= nextFireTime)
  {
     FireProjectile();
  }

} }

function OnTriggerEnter(other : Collider) { if(other.gameObject.tag == "Enemy") { nextFireTime = Time.time+(reloadTime*.5); myTarget = other.gameObject.transform; } }

function OnTriggerExit(other : Collider) { if(other.gameObject.transform == myTarget) { myTarget = null; } }

 function FireProjectile()
 {
    audio.Play();
    nextFireTime = Time.time+reloadTime;
    
    var m : int = Random.Range(0,6);
    var newMissile = Instantiate(myProjectile, muzzlePositions[m].position, muzzlePositions[m].rotation);
    newMissile.GetComponent(Projectile_Missile).myTarget = myTarget;

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cobalt60 · Aug 04, 2012 at 05:32 AM 0
Share

Sorry the question that I asked is not perceptible in the way I want it. What I meant to get at, is that I would like to change the script to be able to shoot different models of projectiles randomly. Right now it can shoot one model. Which say is a blue ball. It would be nice for it to be able to shoot say a blue, orange, green, and red ball. Hope this clears it up a bit.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Benproductions1 · Aug 04, 2012 at 11:04 AM

easy :D

 var Missiles:Transform[];
 //Add that to the start and make myProjectile a private variable and a Transform var
 //and in unity add the prefabs to the list
 function FireProjectile() {
     //Add this to your fire function
     myProjectile = Missiles[Random.Range(0, Missiles.length-1)];
 }

Hope this helps :)

Benproductions1

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Tank Turret move on XAxis by Mouse XAxis 1 Answer

enemy AI script 3 Answers

is it possible to use the enter and exit script to enter a turret? 0 Answers

Trouble with selective projectile script 0 Answers

Easy Animation/Modeling question 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges