Question by
bluemetal · May 28, 2017 at 02:21 PM ·
c#rigidbodyinstantiateiskinematic
stop the objects for a while
Hello
I have rolling stones on my scene, the stones are throwing from the cannon in small part of time.
I want to stop the stones and throwing it for a while when Player drag the the lever on, how could I do it? I tried the function: Time.timeScale = 0; but it stops all the game, I want only stop movement of the stones and throwing from the cannon, how could I do that in C#?
I know that i have to use "Is Kinematic" on each stone Rigidbody instantiate, how can i do? It's cannon script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class stonelauncher : MonoBehaviour {
private float number = 10;
public float time = 2.7f;
public Rigidbody stonePrefab;
public Transform stonePosition;
void Start () {
StartCoroutine (Spawn_stone());
}
IEnumerator Spawn_stone() {
for(var i = 0; i < number ; i = i + 0) {
Rigidbody stoneInstance;
stoneInstance = Instantiate (stonePrefab, stonePosition.position, stonePosition.rotation) as Rigidbody;
stoneInstance.AddForce (stonePosition.right * 7, ForceMode.Impulse);
yield return new WaitForSeconds (time);
}
}
}
Thanks for all advices and sorry for my poor english.
Comment
Answer by Bill9009 · May 28, 2017 at 10:23 PM
With this method you will have to make the stones have the tag name of "Stone" and create a boolean for the lever. Code:
using UnityEditor;
bool lever;
void Update () {
if(lever)
foreach(GameObject g in GameObject.FindGameObjectsWithTag("Stone"))
g.GetComponent<Rigidbody>().velocity = Vector3.zero;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612122955im_/https://answers.unity.com/themes/thub/images/avi.jpg)