Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by LLIV · Feb 07, 2016 at 08:32 PM · scripting problemscript errorscriptingproblem

Can't get script to repeat

 using UnityEngine;
 using System.Collections;
 [RequireComponent(typeof(LineRenderer))]
 public class Roller : MonoBehaviour {
     public int angle_Neg;
     public Animator Anim;
     private GameObject PlayerOBJ;
     private LineRenderer LR;
     private Transform LE;
     private bool Following = false;
     protected Transform Head,LO;
     public float Charge;
     private bool Fire;
     public float RequiredCharge;
     private float StartTime = -1f;
     public bool Debugging = false;
     public Color Start_C;
     public Color Stop_C;
     public float Cooldown;
     void Start () {
 //        Anim = GetComponent<Animator>();
         LR = GetComponent<LineRenderer>();
         Head = transform.GetChild(1).transform; //Get the head
         LO = Head.GetChild(0).transform;
     }
     void Awake () {
         PlayerOBJ = Settings.PlayerOBJ;
     }
     void Update () {
         if (PlayerOBJ == null ) {
             PlayerOBJ = Settings.PlayerOBJ;
         }
         
 //        Anim.SetBool("ScriptControlsHead",false);
         if (this.transform.GetComponent<AIPath2DTopDown>().CanSeePlayer){
 //        if (!Physics.Linecast (transform.position, PlayerOBJ.transform.position)) {
             FollowPlayer();
             if (!Following) {
                 Following = true;
                 
             }
             if (Following&&StartTime==-1f){
                 StartTime = Time.time;
                 if (Debugging) {Debug.Log (StartTime+"Starting");}
 //                LR.SetColors(Start_C,Stop_C);
             }
             if (StartTime + RequiredCharge > Time.time &&!Fire){
                 float a = Mathf.Lerp(0f,1f,Time.time/RequiredCharge);
                 float c = Mathf.Lerp(0.1f,.01f,Time.time/RequiredCharge);
                 LR.SetWidth(.01f,c);
                 Start_C.a = a;
                 Stop_C.a = a;
                 LR.SetColors(Start_C,Stop_C);
             } else {
                 Fire=true;
                 LR.enabled= false;
                 
                 if (Debugging) {Debug.Log (Fire+"Fire");}
                 float a = Mathf.Lerp(1f,0f,Time.time/RequiredCharge);
                 Start_C.a = a;
                 Stop_C.a = a;
                 LR.SetColors(Start_C,Stop_C);
                 StartCoroutine( Cool());
             }
         } else {
             Following = false;
             LR.enabled = false;
             StartTime = -1f;
             LR.SetWidth(.01f,.1f);
             
         }
     }
     void FollowPlayer () {
         // angle_Neg was added for testing it's just 90deg (to offset the rotation to what it is now)
         LR.SetPosition(0,LO.position);
         LR.SetPosition(1,PlayerOBJ.transform.position);
         Vector3 dir = PlayerOBJ.transform.position - LO.position;
         float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
         Head.rotation = Quaternion.AngleAxis(angle-(angle_Neg), Vector3.forward);
     }
     IEnumerator Shoot () {
 //        if (Fire){LR.enabled= true;}
         LR.SetPosition(0,LO.position);
         LR.SetPosition(1,PlayerOBJ.transform.position);
 //        if (Fire) {yield return new WaitForSeconds(.5f); Fire = false; } else {
 //            LR.enabled = false;
 //        }
         return null;
     }
     int JE = 0;
     IEnumerator Cool () {
         if (JE < 1){
         JE += 1;
         LR.enabled= false;
         yield return new WaitForSeconds(Cooldown);
         } else {
         StartTime = -1f;
         Following = false;
         LR.enabled= true;
         Fire = false;
         JE = 0;
         }
     }
     
 }

I can't get this script to repeat. It runs correctly once but then just dies on me.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

43 People are following this question.

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

Related Questions

After converting c# Script, Unity is giving errors on multiple lines which were fine before. 0 Answers

It won't let me use it on my character, and says it needs to derive from MonoBehaviour,It won't let me put this script onto my character, it says it needs to derive from MonoBehaviour 1 Answer

How do you copy an image from the clipboard into an ui image? 0 Answers

Unity 5 checking if player isGrounded 1 Answer

How to reassign a new script reference to the same variable that previously had the same script with another reference? 0 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