hi. I want to increase rope speed every rope spawn. because otherwise my game is being easy. i want becloud the game. how can i do this. my code is below.
Spawn Code:
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public Transform prefab;
public float width = 3;
public float second = 1;
private float sum;
private bool create = true;
void Update()
{
if(create)
StartCoroutine("CreatePrefab");
}
IEnumerator CreatePrefab()
{
create = false;
sum += width;
sum += second;
Instantiate(prefab, new Vector3(sum, 0, 0), Quaternion.identity);
yield return new WaitForSeconds(second);
create = true;
}
}
SwingForce (Rope Speed)
using UnityEngine;
using System.Collections;
public class SwingForce : MonoBehaviour {
public float forceStrength = 5.0f;
public float maxSpeed = 3.0f;
public float timePerOneSide = 2.0f;
private Rigidbody2D rb;
private Vector3 force;
private float timer = 0.0f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
timer = timePerOneSide;
}
void Update()
{
timer += Time.deltaTime;
if(timer >= timePerOneSide)
{
force = new Vector3(forceStrength *= -1, 0, 0);
timer = 0.0f;
}
if(rb.velocity.sqrMagnitude <maxSpeed)
rb.AddForce(force);
}
}